Status update: generic specializer

Brian Goetz brian.goetz at
Mon Aug 25 20:36:47 UTC 2014

We've gotten the generic specializer to a point where it can do quite a 
lot; I've pushed code to the jdk/ repo so that specialization now can 
happen on the fly through classloading hacks.

Maurizio has already posted details on the compiler part of the 
implementation.  To opt into specialization, decorate a specializable 
type variable with the "any" modifier:

class Box<any T> {
     T element;

     Box(T t) { this.t = t; }

     T get() { return t; }

     void set(T t) { this.t = t; }

When used as a raw type, or with reference types as the instantiation of 
T, things will behave exactly as before.  When used with primitive 
instantiations of T, a new class will be specialized on the fly when 
needed, rewriting T to its specialized value in interface and 

There are *many* limitations.  But, it is at the point where a lot of 
things work already, and people may well want to play with it, and you 
should be able to just use javac and java from the valhalla build and do 
some reasonable simple things with specialized classes.

Next up: specializing ArrayList<int>.

Have fun!

More information about the valhalla-dev mailing list