[request for review] 4877954: RFE: Special syntax for core interfaces

Dmytro Sheyko dmytro_sheyko at hotmail.com
Mon Nov 12 13:42:27 PST 2007


Hi,

This is a request for review of patch to KSL, which partially implements
bug#4877954 (using relational operators was mentioned there in passing).

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4877954
4877954: RFE: Special syntax for core interfaces
Part: Relational operators (<,<=,>,>=) for classes that implement
Comparable<T>

General rule:
if lhs is expression if type that implements Comparable<T> and rhs is
expression of type that extends/implements T, then relational expression

     lhs op rhs

is considered identical to

     lhs.compareTo((Object) rhs) op 0

where op is one of relational operators (<,<=,>,>=)


Special cases:

1. Compile time error occurs if lhs or rhs is null (despite null can be
casted to Comparable<T> or to any T).

2. Expressions of boolean type (i.e. boolean or Boolean) are considered
comparable so that 'false' is less than 'true'. Both operands are evaluated
always.

3. If type of lhs and rhs is numeric type (i.e. any of byte, Byte, short,
Short, char, Character, int, Integer, long, Long, float, Float, double,
Double), then comparison is performed with unboxing (when necessary) and
immediate primitive value comparison rather than boxing and invoking
compareTo method. This is necessary to be able compare numbers of any
primitive or wrapper type with numbers of any other primitive or
wrapper type. Another reason is to preserve backward source compatibility
since comparison of primitive floating-point numbers is slightly different
than comparison of wrappers using compareTo (in cases of -0.0 and NaN).

This change is controlled by command line option -XDcomparable.

Attached svn diff. 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RFE4877954-comp.diff
Type: application/octet-stream
Size: 8949 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20071112/758a85b6/RFE4877954-comp.diff 


More information about the compiler-dev mailing list