Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.1.7, 2.3.0, 2.4.0-beta-3
-
None
Description
There is an inconsistency between the behaviour in runtime and in the static type checker when accessing the class of a Java primitive type. Suppose we have the following code:
void runMethod (){
int i = 10
println(i.class)
}
runMethod()
If I run this in the Groovy console everything runs fine, autoboxing is performed and 'class java.lang.Integer' is printed as the output. However, if I annotate the method with @groovy.transform.TypeChecked, there is an exception stating '[Static type checking] - No such property: class for class: int'. The same happens if I don't declare a variable and try to use a literal int instead.
As far as I know, this happens with all the primitive types. In addition, trying to access their metaClass works well with or without the type checking enabled.
I attach some of the examples I could come up with.