compareTo and deriving
Zheka Kozlov
orionllmain at gmail.com
Mon Dec 4 14:19:10 UTC 2017
What is the implementation of compareTo() for Point?
2017-12-04 20:34 GMT+07:00 Remi Forax <forax at univ-mlv.fr>:
> Ok,
> record/data class currently provides getters and toString/equals/hashCode,
> what if i want to add a compareTo.
>
> In Haskell, it's easy, one can use 'deriving', in Java, it can be written
> that way,
> record Point(int x, int y) implements Comparable<Point>
> deriving equals, hashCode, toString, compareTo;
>
> For the compiler, the method exists in the supertypes, so the signature of
> the method can be computed from the super types,
> after each generated method use an invokedynamic with the same meta
> protocol (a list of getters),
> so if by convention "equals", "hashCode", "toString", "compareTo" are the
> names of some bootstrap methods in a class DerivingMetaFactory,
> it can be trivial for a JDK developer to add a new bootstrap method
> without having to change the JLS.
>
> So my point is, that we can specify once how the compiler should generate
> codes for any generated methods in an extensible way.
>
> regards,
> Rémi
>
>
>
More information about the amber-spec-observers
mailing list