IdentityObject and InlineObject

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Dec 9 14:45:19 UTC 2019


On 06/12/2019 22:28, Brian Goetz wrote:
>
>> package java.util;
>> public class IdentityHashMap<E extends IdentityObject> { ... }
>
> This one has an easy out:
>
>     public class IdentityHashMap<E extends Object&IdentityObject> { ... }
>
> I was hoping your example would be type bounds, since they're easily 
> amenable to this trick (either explicitly, or with compiler help.) Got 
> more?
>
>
Uhm - doing this change is certainly binary compatible (the extra bound 
is erased) - but it's not source compatible - every client using 
IdentityHashMap<Object, ...> would fail to compile now, right?

E.g. imagine code like this:

public class Foo {

public Map<Object, String> cache = new IdentityHashMap<>();

}

With the proposed bound change, two things will happen:

1) the inferred type of the 'new' expression will change
2) the inferred type as of (1) will be incompatible with the type in the 
LHS -> error

To fix the issue, you have to change the LHS type - if this is a public 
API, this will then trigger more downstream issues (again, not about BC, 
but about source compatibility).

Maurizio



More information about the valhalla-spec-experts mailing list