Skip to content

Instantly share code, notes, and snippets.

@dwarszawski
Last active September 20, 2016 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwarszawski/89ab9f1f03304755728446d5e3cb7297 to your computer and use it in GitHub Desktop.
Save dwarszawski/89ab9f1f03304755728446d5e3cb7297 to your computer and use it in GitHub Desktop.
groovy compiler does not resolve generics properly
import groovy.transform.CompileStatic
@CompileStatic
public abstract class AbstractClass<A, B> {
private final Class<A> aClass
private final Class<B> bClass
AbstractClass(Class<A> aClass, Class<B> bClass) {
this.aClass = aClass
this.bClass = bClass
}
void print() {
println("class A {$aClass} and class B {$bClass}")
}
}
@CompileStatic
public class SomeImpl extends AbstractClass<String, Integer> {
SomeImpl() {
super(Integer, String) //this should not compile
}
}
AbstractClass object = new SomeImpl()
object.print()
@dwarszawski
Copy link
Author

Expect compilation error but actually the result is as follow
Result: class A {class java.lang.Integer} and class B {class java.lang.String}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment