Fwd: Remi's comments on Any

Gavin King gavin at hibernate.org
Mon Jan 5 01:20:43 UTC 2015

On Mon, Jan 5, 2015 at 2:08 AM, Thomas W <twhitmore.nz at gmail.com> wrote:

> I am very happy to disregard the "tagged union" approach & not actually
> implement an Any primitive in the VM.

So while it's certainly not *necessary* in order to get Any in Java's
type system, it still seems to me like it's something that would make
the JVM much more useful. I want to hear from someone compiling
*dynamic* langs like JavaScript to the JVM what they think about it.

> But what if we introduce Any as a 'nominal' type in the type-system, but
> implemented as a reftype/ or boxed object with equals() and hashCode()
> methods. That would give us the exact same performance of today for
> unspecialized code, but a better type-system to describe ArrayList<int>
> descending from ArrayList<Any>.

Right, that was the first of my implementation suggestions above. To
recap: use exactly the implementation ("specialization") proposed
today for concrete instantiations like ArrayList<int> and
ArrayList<Object>. But use boxing for the much less common
instantiation ArrayList<Any>.

> I am _totally_ happy with reftypes & boxing as our base case, only code
> which has been specialized is expected to perform better, performance on
> List<Object> is not at issue.

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!

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.

I'm not advocating that, however. FTR, I don't see anything wrong with
ArrayList<Any>, whether implemented using boxing or using a tagged

Gavin King
gavin.king at gmail.com

More information about the valhalla-dev mailing list