do generic member functions have 2 physical versions
Andy Nuss
andrew_nuss at yahoo.com
Fri Apr 19 17:08:23 PDT 2013
Hi,
Lets say I have a class:
public abstract class AbstractVar<T> {
public abstract T get ();
public abstract void set (T t);
}
and a subclass for a general T:
public class Var<T> extends AbstractVar<T> {
private T t;
public T get ()
{
return t;
}
// ??? is the byte code signature the same as if: set (Object t)
public void set (T t)
{
this.t = t;
}
}
and another for a specific kind of T:
public class VarString extends AbstractVar<String> {
private String s;
public String get ()
{
return s;
}
public void set (String s)
{
this.s = s;
}
}
My question regards the generated bytecode and virtual functions. It would see that for Var<T>, since the member variable is of type T, it really is of type Object, so that Var<T> can work for all parameterizations of T without bloating the generic. Yet VarString implements the same abstract interface. It would seem that with Var<T>, the setter actually takes an argument of type Object, while the setter in VarString takes an argument of type String, making them different functions that satisfy the same virtual function in the abstract contract. If so, how does it work, especially given that the two non-abstract getters would have the same signature and different results?
Thanks,
Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20130419/4477b10b/attachment-0001.html
More information about the hotspot-compiler-dev
mailing list