Note that there are some explanatory texts on larger screens.

plurals
  1. POImplement Comparable<T> in a generic superclass
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COTechnically, one could "break the implied contract" and create a concrete class which was comparable to some other class with something like "class Foo extends AbstractEntity<Long,User>", but I'm not that worried about cases where people go out of their way to write garbage.
      singulars
    2. COIs there any reason you must use `Comparable` rather than `Comparator`? The `Comparator` method seems more suitable for use with inheritable types. If you will need to be able to compare items without having a `Comparator` handy, but you will control the types in question, it might also be helpful to define an interface which allows an object to be asked for a `Comparator` that is suitable for use with it. If one has a `Comparator` that can handle all items in an array, one can cleanly sort the array even if the items are of different types.
      singulars
    3. CO@supercat - Mainly because it would require fewer client-side changes to reap the benefits. If I used a Comparator, the client code would have to acquire the Comparator and explicitly use it (either by creating a collection that uses it or by passing it to a sort function). They would have to do this everywhere they want to sort. This way, if the client code happens to place the objects of this type in a naturally sorted Collection (or they call a natural sort function), it will just start working.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload