Type equality for values
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Aug 1 18:27:19 UTC 2014
On 01/08/14 11:23, Maurizio Cimadamore wrote:
> Right - I would expect that to already be working (modulo the fact
> that I have not really tested integration of 'any' with value types
> that much - yet).
Let me backtrack a bit - currently the spec (15.21.3) demands that the
equality should be accepted if one type is castable to the other. I
believe in all the examples I've seen so far, that's the case, as there
is always a chance that the type-variable will be instantiated with the
same type, so the cast must be allowed.
Maurizio
>
> Maurizio
>
> On 01/08/14 11:07, Brian Goetz wrote:
>> Certainly if we cannot prove T=U then I think this equality
>> comparison makes no sense. But if we have
>>
>> <any T> boolean foo(A<T> a, A<T> b) { return a==b; }
>>
>> this does make sense (assuming we are comparing values for state
>> equality via ==).
>>
>>
>> On Aug 1, 2014, at 10:10 AM, Paul Govereau <paul.govereau at oracle.com>
>> wrote:
>>
>>> The following code is valid for reference types:
>>>
>>> class A<T> {
>>> int x = 0;
>>>
>>> <T,U> boolean foo(A<T> a, A<U> b) {
>>> return (a == b);
>>> }
>>> }
>>>
>>> However, I don't think this makes sense for value types. In the case
>>> of reference types, the "top" is a realizable type, namely Object;
>>> but, for values the "top" is not realizable?
>>>
>>> final __ByValue class A<T> {
>>> final int x = 0;
>>>
>>> <any T, any U> boolean foo(A<T> a, A<U> b) {
>>> return (a == b); // <<--- type error ??
>>> }
>>> }
>>>
>>> Should this be a type error?
>>>
>>> Paul
>
More information about the valhalla-dev
mailing list