Static fields and specialization

Brian Goetz brian.goetz at oracle.com
Mon Jan 12 16:11:40 UTC 2015


> You probably misunderstood me (again) :(
>
> Richard suggested that you can keep speed of Optional.empty() by
> creating separate layers for <ref T>, <int T>, etc...

Remember, for value types (hopefully Optional will be one), 
instantiation is essentially free, and in most cases where this idiom is 
used, it is the allocation that we're trying to optimize away.  So the 
idiom of "cache one and return the same instance", in these cases, can 
be retired.

I realize this still doesn't help us for reference types, like 
Collections.emptyList(); this point got made a while ago (so it didn't 
occur to me we were still talking about it.)




More information about the valhalla-dev mailing list