On Wed, 14 Oct 2020 18:09:16 GMT, Mandy Chung <mch...@openjdk.org> wrote:
>> @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); That sounds reasonable to me. Thanks for looking into it. ------------- PR: https://git.openjdk.java.net/jdk/pull/498