Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy Generics failure

Besides groovy is way more dynamic then java...

Why is this a compile time error in groovy (unexpected token <):

interface A {
     <T> T getByClass(Class<T> clazz)
}

How do I write this the groovy way?

like image 742
matcauthon Avatar asked Jul 09 '12 12:07

matcauthon


1 Answers

The Groovy parser does not handle method signatures beginning with Generic information...

It parses if you add the public modifier:

interface A {
  public <T> T getByClass( Class<T> clazz )
}

Though I don't believe you'll gain any type checking at compile time for adding this annotation

like image 111
tim_yates Avatar answered Sep 25 '22 21:09

tim_yates