On Wed, 14 Oct 2020 18:15:19 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:
>> For the common cases, the application should know the type of the referent >> and using `T` in `refersTo` will benefit >> from the compiler type checking. For the unknown type case, cast to >> `Reference<Object>` is not ideal but reasonable? >> something like this: Reference<Object> r = (Reference<Object>) ref; >> r.refersTo(obj); > > That sounds reasonable to me. Thanks for looking into it. I just want to note that if you have a `Reference<SomeType> ref` at hand, you can not just do: Referemce<Object> r = (Reference<Object>) ref; ...since those generic types are not related. You have to do something like: @SuppressWarnings({"unchecked", "rawtypes"}) Referemce<Object> r = (Reference) ref; which is very unfortunate. Comparing this method with for example `Collection.contains(Object element)`, you can see that Collection API has made a decision to not bother with T here. That was also due to keeping old code compatible when migrating from pre-generics Java to generified Collection, but as @dfuch noted, we have a migration story here too. We will be migrating `obj == ref.get()` to `ref.refersTo(obj)` ... Mind you that this is a boolean expression fragment which might be written inline surrounded with other parts of expression. So you'll be forced to split that into assignment with @SuppressWarnings and an expression or you will have to force the whole expression or method to @SuppressWarnings. I don't know if type "safety" is forth it here. ------------- PR: https://git.openjdk.java.net/jdk/pull/498