Hi,
The following Groovy code prints "it works"
def printIt(Class<? extends Exception> clazz) {
println "it works"
}
printIt(String.class)
even though the parameter doesn't satisfy the constraint Class<? extends Exception>
My understanding is that this is because:
- Type erasure in Java generics means there's no run-time generic type checking
- There is no compile-time type checking in Groovy
These two points means there's effectively no checking of bounded generic types in Groovy. Is there any way I can check (at runtime) that the Class
object passed to printIt
satisfies the constraint ? extends Exception
Thanks, Don