Skip to content

Instantly share code, notes, and snippets.

@cevaris
Created April 19, 2014 22:10
Show Gist options
  • Save cevaris/11099129 to your computer and use it in GitHub Desktop.
Save cevaris/11099129 to your computer and use it in GitHub Desktop.
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;
}
}
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;
}
}
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