I have the following fragment of code:
class BaseClass {
public Integer getX() {
return 5;
}
}
class InheritedClass extends BaseClass implements Interface {
}
interface Interface {
public Number getX();
}
public class Test5 {
public static void main(String[] args) throws Exception {
System.out.println(InheritedClass.class.getMethod("getX").getReturnType());
}
}
this code returns java.lang.Number, which is very strange to me, because BaseClass's getX method returns java.lang.Integer. And the most interesting is that if BaseClass implements Interface, the returned type is java.lang.Integer... Is this a normal behaviour?