Created
April 19, 2014 22:10
-
-
Save cevaris/11099129 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Y implements Comparable<X> { | |
int yTest; | |
@Override | |
public int compareTo(X o) { | |
if(this.yTest < o.xTest) return -1; | |
if(this.yTest > o.xTest) return 1; | |
return 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class X implements Comparable<Y> { | |
int xTest; | |
@Override | |
public int compareTo(Y o) { | |
if(this.xTest < o.yTest) return -1; | |
if(this.xTest > o.yTest) return 1; | |
return 0; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Compare { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
X x = new X(); | |
x.xTest = 10; | |
Y y = new Y(); | |
y.yTest = 100; | |
System.out.println("x.compareTo(y) == -1: " + (x.compareTo(y) == -1)); //True | |
System.out.println("y.compareTo(x) == 1: " + (y.compareTo(x) == 1)); //True | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment