As mentioned before, Eddy and I discovered a problem with type variables in code generated by the Mint compiler. We have now fixed this problem in the new release of Mint and DrJava with Mint: August 30, 2010 (r15716). The latest release is, as always, available from the Mint implementation page:
The problem occurred when the programmer used a type variable inside a bracket. An example of this would be a generic method like this:
1 2 3 4 | public separable <X> Code<X> fun(Code<X> c1, Code<X> c2) { return <| ( `(lfTest.eval(e,f).booleanCodeValue()) ? `c2 : `c1 ) |>; } |
This caused Mint to generate 2nd stage code that contained the type variable X
unbound. Unfortunately, the types are erased, and there is no way to find out what type X
actually refers to at runtime, e.g. by writing something like X.class
(this generates the Java compiler error “cannot select from a type variable”).
To get around this problem, we now require a final instance of type Class<X>
to be in scope for every type variable X
. For example, in the generic method above, there is a type variable X
that is being used in the bracket. Therefore, we now have to have a final instance of Class<X>
somewhere in scope, for example as a method parameter.
1 2 3 4 5 | public separable <X> Code<X> fun(Code<X> c1, Code<X> c2, final Class<X> xc) { return <| ( `(lfTest.eval(e,f).booleanCodeValue()) ? `c2 : `c1 ) |>; } |
That’s all that is necessary. The variable xc
is not actually used in the code, it just needs to be in scope.
(Re-posted from The Java Mint Blog.)