PROPOSAL: Equivalence operators (formerly titled
vapor1 at teleport.com
Fri May 8 14:38:11 PDT 2009
Thanks for your comments.
The proposal already does what you suggest, although I agree it is not clear from the section you quoted (which was only intended to be a brief feature summary). If you look in the specification section, you will find that in a case like "a < b" where a is Float and b is float, that since both types are convertible to a primitive type, that this conversion will be done before the operation is attempted (possibly triggering a NullPointerException on unboxing), yielding the same results as would occur in Java now.
In some ways, I think it would be nice to have the ># and <# operators return true if both of their operands are null, even if both operands are typed as boxed primitives. This would be more similar to how ## and !# work and would be consistent for all operators if you assume that null "is equivalent to" null. I am considering changing the proposal to allow this. (Currently this operation would provoke a NullPointerException during unboxing, according to proposal version 3 and before). < and > would not be affected by this, of course. Comments?
>From: Mark Thornton <mthornton at optrak.co.uk>
>Sent: May 8, 2009 3:05 AM
>To: Derek Foster <vapor1 at teleport.com>
>Cc: Project Coin <coin-dev at openjdk.java.net>
>Subject: Re: PROPOSAL: Equivalence operators (formerly titled "Sameness operators") (Version 3)
>Derek Foster wrote:
>> and adds additional overloadings to existing operators:
>> a < b a.compareTo(b) < 0, or a < b for primitive types.
>If 'a' is Float (or Double) and 'b' is float (double), then you have to
>unbox 'a' to apply the primitive comparison and not box 'b' and apply
>.compareTo. Boxing 'b' to apply compareTo would be a breaking change.
More information about the coin-dev