On Tue, 13 Oct 2020 08:49:23 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:
>> @dfuch I would expect the users of `refersTo` should know the type of the >> referent to be compared, i.e. it should know >> the parameter type of a Reference object. Do you have any specific use >> case in mind that you have a `Reference<?> >> ref` but wants to compare a referent of unknown type? > > @mlchung I have often used a `Reference<?>` in tests - but my main usage > there would be to call `ref.refersTo(null)` > which works in all cases. My main concern here however is that using `T` in > `refersTo` seems to go against the > advertised usage of the method - I mean - if I have an object `obj` of type > unknown, I can always do `obj == ref.get()` > whatever the parameter type of `ref` is. But I won't be able to call > `ref.refersTo(obj)` unless I use raw types and > suppress warnings. So I just wanted to check that this was intentional. 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); ------------- PR: https://git.openjdk.java.net/jdk/pull/498