Questions about Specialization
Brian Goetz
brian.goetz at oracle.com
Mon Aug 25 21:23:48 UTC 2014
> 1. Could you confirm me that, if I have a specialized type Box<any T> :
> Box<T> will always use reified type when T is a primitive or a type-value.
> Box<T> will always use erasure when T is an object type
> (interface/enum/class).
Currently, yes; of course this may change.
> 2. What's about using hashCode()/equals()/toString() in Box<any T> ?
> Exemple :
>
> public class Box<any T> {
>
> private T value;
>
> @Override
> public int hashCode() {
> return value.hashCode();
> }
> }
>
> Is it possible ?
> Eg with Box<int> "value.hashCode()" will be corrected to
> "Integer.hashCode(value)"...
Open question; the answer likely will come from conditional methods
("where" methods).
> 3. I suppose it's forbidden to use the "any" modifier with variance, eg :
Yes. Also with bounds.
> public class Box<any T extends Iterable<T>> { // compile error ?
>
> But what's about Comparable, Serializable or Cloneable ?
> I think it could be useful to do something like this :
Yes, it could be useful; it could also add excessive complexity, so
we're doing the prudent thing and only biting off what we can currently
chew. We'll return to these questions when we're deeper in the
exploration of value types (related).
More information about the valhalla-dev
mailing list