Why is return-type covariance enforced for hidden static methods?
问题 This code won't compile because of the String return type of the staticMethod in Child . class Parent { static void staticMethod() { } } class Child extends Parent { static String staticMethod() { return null; } } I know that JLS 8 in §8.4.8.3, "Requirements in Overriding and Hiding" says: If a method declaration d1 with return type R1 overrides or hides the declaration of another method d2 with return type R2, then d1 must be return-type-substitutable (§8.4.5) for d2, or a compile-time error