Does any Java Interface implicitly implements java.lang.Object?
This question arose when I did something like this:
public static String[] sizeSort(String[] sa) {
Comparator<String> c = new Comparator<String>() {
public int compare(String a, String b) {
if (a.length() > b.length()) return 1;
else if (a.length() < b.length())
return -1;
else
return 0;
}
};
// more code
}
It worked fine even though I did not implement equals method of this interface.
Your answers clears this up. But does any one know if above is anonymous local inner class or named local inner class?
Sort of. Citing the Java Language Specification:
Note that
Objecthas a number of final and protected methods that all interfaces “inherit” this way, and you couldn’t have those modifiers in an interface (which would be implied by your “implements java.lang.Object”).