I have a generic java interface Id<T> with a single method T getId() and a class MyClass that implements Id<Long>. When I inspect the methods declared on MyClass using java reflection, I see two methods: one with return type Long, and one with return type Object. Where does the second method come from and how can I remove it?
Here is the source:
package mypackage;
import java.lang.reflect.Method;
public class MainClass {
public static void main(String[] args) {
for (Method method : MyClass.class.getDeclaredMethods()) {
System.out.println(method);
}
// prints out two lines
// public java.lang.Long mypackage.MyClass.getId() <-- ok
// public java.lang.Object mypackage.MyClass.getId() <-- not ok
}
}
interface Id<T> {
T getId();
}
class MyClass implements Id<Long> {
@Override
public Long getId() {
return new Long(0);
};
}