Draft proposal: allow the use of relational operators on Comparable classes

Neal Gafter neal at gafter.com
Thu Mar 12 12:43:59 PDT 2009


Agreed.  Like it or not, the language has already taken a position on
this: all enum types are ordered and comparable.  You can ignore that
fact if you want, which as kevin pointed out most uses do, but when
its helpful it is very nice to have it automatic.

Given that all enums are already ordered, if anything is to be done
with the relational operators for enums, they should all get support
of the relational operators.

On Thu, Mar 12, 2009 at 12:20 PM, Joshua Bloch <jjb at google.com> wrote:
> Alex,
>
> Arguably it's a bit too late: the marker (or whatever) should have triggered
> whether the enum implemented the Comparable interface as well:(
>
>       Josh
>
> On Thu, Mar 12, 2009 at 12:19 PM, Alex Miller <alexdmiller at yahoo.com> wrote:
>
>>
>>
>> Kevin Bourrillion <kevinb at google.com> said:
>>
>> > But focusing on enum types sidesteps one set of problems in favor of
>> > another.  That being that most user-defined enum types do not actually
>> have
>> > any logical order, and many that _seem_ to have an order do not actually
>> > have that order guaranteed.
>>
>> I would love to have the relational operators on enums...when it makes
>> sense.  What if there was a marker interface that your enum could implement?
>>  Something like OrderedEnum?
>>
>> I suppose it might be bad form to have the language behavior as to whether
>> something is legal be dependent on a marker interface.  But you guys are the
>> experts.
>>
>> Alex
>>
>>
>
>



More information about the coin-dev mailing list