public class EqualsTest {
public static <T> boolean equalTest(T o1, T o2) {
return o1.equals(o2);
}
public static void main(String[] args) {
EqualsTest et1 = new EqualsTest();
EqualsTest et2 = new EqualsTest();
System.out.println(et1.equals(et2));
System.out.println(equalTest(et1, et2));
}
public boolean equals(Object o) {
if (o instanceof EqualsTest) {
System.out.println("equals(Object)");
return true;
}
return false;
}
public boolean equals(EqualsTest et) {
System.out.println("equals(EqualsTest)");
return this.equals((Object)et);
}
}
public class EqualsTest { public static <T> boolean equalTest(T o1, T o2) { return
Share
There is none, it is implicit. Since it does not explicitly
extendsany class, it will implicitly extendObject. And since Object has a no-arg constructor, it will implicitly call up to that one.Really, the class could contain a constructor written as this, and it would be equivalent:
You cannot use implicit constructors if the class you extend does not also have a ‘no-arg’ constructor (whether implicit or explicit). If you provide any explicit constructor, there will be no implicit no-arg constructor created for you.