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

Daniel Fuchs dfuchs at openjdk.java.net
Tue Oct 13 08:52:10 UTC 2020


On Mon, 12 Oct 2020 21:46:37 GMT, Mandy Chung <mchung at openjdk.org> wrote:

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

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

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

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



More information about the hotspot-gc-dev mailing list