Any as a simple reftype base to the type-system
Thomas W
twhitmore.nz at gmail.com
Mon Jan 5 02:41:16 UTC 2015
Hi Gavin, people,
Traditionally Object has effectively been "Any" in the Java type system --
with builtin boxing/ unboxing to use it for primitives.
> Well the really interesting thing is that in principle you don't even
> necessarily need to allow a concrete instantiation ArrayList<Any>! You
> could prevent people from writing "new ArrayList<Any>()" if you
> prefer, and I for one would still be happy enough!
Well, to avoid member collisions & actually achieve specialization,
ArrayList<int>.class != ArrayList<Object>class. But if 'Any' is
effectively treated as a non-lockable reftype super to Object.. could we
just redefine collections to be parameterized on <? extends Any> and be
done with it?
- Any would implement (essentially same as) Object, without the locks.
- Any[] would implement same as Object[].
- boxing/unboxing from primitives would be same.
- equals(), hashCode() and toString() would be available.
If we can do the above, I don't necessarily see problems instantiating
ArrayList<Any>.
There is a need for wide ecosystem compatibility, but the above principles
seem to cover quite much. (These are also similar to the issues Stephen
Colebourne raises on separating Lockable from Object, but taken from a
different angle.)
> If you did that, instantiations like ArrayList<? extends Any> would
> only be *use-site* instantiations. This would still be enough fix the
> bothersome properties of the type system that I'm objecting to.
Yes, I think the type system is very worthwhile to consider & this is one
of the reasons I am interested in this kind of approach.
Regards,
Thomas Whitmore
More information about the valhalla-dev
mailing list