jdaugherty commented on issue #14130:
URL: https://github.com/apache/grails-core/issues/14130#issuecomment-2799715363

   See the groovy mailing list for a full discussion, but here's a snippet of 
Paul King's response on this issue:  
   
          it is illegal code in Java, Groovy has just been previously ignoring 
the error and treating it like "Object".
   
   And more aptly: 
   
           It isn't necessarily obvious from your examples but if you had:
   
           class Wrapper<T> {
               static final T someConst
           }
   
           Then Wrapper<String> and Wrapper<Integer> would have dramatically
           different ideas about what the shared constant's type is. That's why
           Java flags it as an error. Earlier Groovy versions just ignored that
           and treated the constant as type Object.
   
   I think Paul's example makes it clear that a static variable can't infer the 
type because it's not on the typed instance.  He does give some possible 
workarounds: 
   
   1. Make the closure an instance variable:
   
         private final Closure<T> noOpClosure = { T v -> return v }
   
   2. Use a static factory method (the T method placeholder here is
         unrelated to the class generics):
   
            private static final <T> Closure<T> getNoOpClosure() {
                 { T v -> return v }
             }
   
   
   Since this was due to an upstream groovy issue, and the code has been 
identified as invalid, I'm going to close this ticket.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to