Idea how to implement VT/VO compatibility in JVM

Stéphane Épardaud stef at epardaud.fr
Thu Jan 22 09:17:33 UTC 2015


On 01/22/2015 09:34 AM, Palo Marton wrote:
>
>
>     But there's no instantiation of "any T" that would let me not know
>     the generic type at compile-time, no? Frameworks that need to
>     traverse collections without having to know what type of thing
>     they're traversing can't do that with value types ATM. Obviously
>     with my proposal they'd box, but at least they could traverse any
>     collection.
>
>
>
> I think that in the end there will be also method like this:
>
> public static <val T> List<__Boxed T> boxedList(List<T> list)
>
> This will return "boxed" view of value type list. From what you write 
> it seems that such method will do exactly what you need - you can cast 
> value type list into boxed list and traverse it as boxed objects.

This would indeed allow frameworks to traverse List<val X> as 
List<Object> without requiring an instantiation of the value type T 
which they cannot possibly know about, but this is more expensive than 
making List<__Boxed T> === List<val T> because it requires wrappers and 
is frankly inelegant.



More information about the valhalla-dev mailing list