Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
It seems like if I use @CompileStatic, a construct like
Car specificCar = somethingWithAGetAtMethod[129]
.. or ..
Car specificCar = somethingWithAGetAtMethod["AZ1235"]
doesn't work. The compiler says: Groovyc: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type com.example.Car
This seems strange. The getAt(..)-method in question obviously return a "Car" here.
This email thread has evidently experienced the same: http://groovy.329449.n5.nabble.com/Unexpected-behaviour-for-getAt-operator-operloading-with-static-compilation-td5744122.html
.. and the theory is that since this is specified on Groovy's extension of Object, which specifies Object getAt(String), then that might be the culprit. Interesting, though, that Object does not seemingly specify getAt(int), but it still gives the exact same compiler error with both int and String.
I had this idea that the subscript-operator was "syntactic sugar", which then makes the compiler error hard to understand.