Idea how to implement VT/VO compatibility in JVM

Palo Marton palo.marton at gmail.com
Thu Jan 22 08:34:40 UTC 2015


>
>
>>  To me the compromise that we can't write code that iterates say, a
>>> list, without knowing at compile-time what type of value-generics it may
>>> hold is a compromise that will haunt Java forever.
>>>
>>
>> This is just incorrect.  You can write a generic method:
>>
>>   <any T> forEach(Collection<T> c, Consumer<T> action)
>>
>
> 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.


In java.util.Collection you have static methods like:

public static <T> List<T> synchronizedList(List<T> list)
public static <T> List<T> unmodifiableList(List<? extends T> list)

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.


More information about the valhalla-dev mailing list