Idea how to implement VT/VO compatibility in JVM

Stef Epardaud stef at epardaud.fr
Thu Jan 22 14:36:56 UTC 2015


 On Thu, Jan 22, 2015 at 02:14:13PM +0000, Maurizio Cimadamore wrote:
> I think both Stephane (and you) and Vitaly have a point; such
> dynamic frameworks have two alternatives:
>
> * keep working the way they do now - which implies List<val T> is
> related to List<?>/List
> * let them be generified, and then use reflection (on steroids) to
> let the right thing happen at runtime
 
Yes, it is possible that you could specialise code at runtime via the
reflection API (perhaps it will already be required by the current proto),
so you could do something like:

Object fieldValue = field.get(instance);
if(Collection.class.isSpecialisedInstance(fieldValue)){
  Method m =
getClass().getMethod("traversalMethod").specialize(fieldValue.getSpecialisedTypeParameters().get(0));
  m.invoke(fieldValue);
}

With:

<any T> void traversalMethod(Collection<T> collection){...}

That requires runtime specialisation but I suppose that the current proto already supports
that in other locations (linking).

TBH, while I find this much less elegant, if the only issue there is with the current proto
is WRT frameworks (the points we've raised), and since there are far less framework code
than user code, and this approach is simpler to implement (if only because there already is
a proto for that), then perhaps that's enough?

I guess the reflection layer will have to do autoboxing for value types the way it already has
to do with primitive autoboxing, so that's about the only thing missing to be able to deal
with compile-time unknown value type argument instantiations. 
-- 
Stéphane Epardaud



More information about the valhalla-dev mailing list