-4

I have developed/implemented a generic compareTo method in Java. So that for any object you define, it will hava a compareTo method. Is this relevant? Please answer and comment.

  • "relevant" to what? – sdgfsdh Jan 29 '18 at 09:51
  • Leave the superior/inferior aside. You can not say that 3 is superior to 1. You just say that is at a distance of 2. So the compareTo is showing how different is an object from other object of the same type. – Alexandru Manescu Jan 29 '18 at 10:00
  • 1
    "Leave the superior/inferior aside" => But that's the nature of the `compareTo` method! Quote from [`Comparable`](https://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html): "This interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class's _natural ordering_, and the class's compareTo method is referred to as its _natural comparison method_." – Seelenvirtuose Jan 29 '18 at 10:14
  • Let's say you intend to compare a bottle of Coca-Cola with a bottle Schweppes(instances of Beverage let's say). And we presume that compareTo will return 3. If you compare a bottle of Schweppes with a bottle of Coca-Cola the result will be -3. And finally, if you compare a bottle of Schweppes with a bottle of Schweppes the result of compareTo will be 0. practically you determine the distance in spatiality. – Alexandru Manescu Jan 29 '18 at 10:37
  • @Aaron, basically the `compareTo` method is really for homogeneous sets – Victor M Perez Jan 29 '18 at 10:40
  • 1
    @VictorHerasmePerez right, my initial reasoning was flawed since `comparesTo` applies to members of a same class anyway. Seelenvirtuose's point is relevant though : you can't have a generic compareTo because not all classes represent sets of objects with total order. [You can't order complex numbers for instance](https://math.stackexchange.com/questions/487997/total-ordering-on-complex-numbers). – Aaron Jan 29 '18 at 10:59
  • Leave total order aside – Alexandru Manescu Jan 29 '18 at 11:19
  • 1
    Please do not vandalize your posts. By posting on Stack Overflow, you've granted a non-revocable right for SO to distribute that content under the [CC BY-SA 3.0 license](https://creativecommons.org/licenses/by-sa/3.0/). By SO policy, any vandalism will be reverted. – iBug Jan 31 '18 at 06:57
  • There is already a library that does that: http://commons.apache.org/proper/commons-beanutils/ –  Jan 31 '18 at 07:11

1 Answers1

3

Go to this site in order to submit proposals. Read the Welcome to the Java Community Process!:

..... Anyone can register for the site and participate in reviewing and providing feedback for the Java Specification Requests (JSRs), and anyone can sign up to become a JCP Member and then participate on the Expert Group of a JSR or even submit their own JSR Proposals.

Also in the How to Contribute section OpenJDK site, they mention these steps:

  1. Become a Contributor
  2. Find something interesting to work on
  3. Discuss your intended change
  4. Submit a patch
  5. Work with your sponsor
  6. Know what to expect

Good luck with that. And please share it with us too

Victor M Perez
  • 2,185
  • 3
  • 19
  • 22