JEP 218: Generics over Primitive Types

Simon Ochsenreither simon at ochsenreither.de
Sat Oct 25 03:02:09 UTC 2014


One thing that's still unclear to me is how variance well be handled.

In current Java, it would be possible to say "variance is declared at 
use-site, so we can just reject such variance annotations when the type 
participating is a value type", but in other languages, this is an issue 
because of variance is declared at declaration-site.

Rejecting all such definitions is a bad idea, because that would mean a 
large percentage of such types could either not be specialized at all, 
or wouldn't be able to be variant anymore, including for reference types.

Given that even Java has now a JEP Draft¹ to add declaration-site 
variance, I think it would be a reasonable idea to figure this out 
before the issue arises.

It would probably make sense to allow such declarations, but specify 
that all variance relations where a value type participates are 
collapsed into an invariant definition.

It is not an obscure issue: This question arises for popular types like 
List[T] or Vector[T].

¹ http://openjdk.java.net/jeps/8043488



More information about the valhalla-dev mailing list