RFR: 8188055: (ref) Add Reference::refersTo predicate [v2]

Mandy Chung mchung at openjdk.java.net
Mon Oct 12 21:49:16 UTC 2020


On Tue, 6 Oct 2020 09:19:32 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/ref/Reference.java line 361:
>> 
>>> 359:
>>> 360:     /* Type-erased implementation of refersTo(). */
>>> 361:     native boolean refersTo0(Object o);
>> 
>> Is there any reason why it can't use the parameter type like `refersTo0(T o)`?  Same for `PhantomReference::refersTo0(T
>> o)`
>
> But should `refersTo` takes a `T`? I mean - if I have a `Reference<?> ref`, the compiler will not let me query
> `ref.refersTo(o)`; is this what we want?

@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?

-------------

PR: https://git.openjdk.java.net/jdk/pull/498


More information about the core-libs-dev mailing list