mardi 24 avril 2018

re-inheritance static field from class and interface

interface A {
    public static String name = "A";
}
interface B {
    public static String name = "B";
}
class X implements A { }
class Y extends X implements B { }
public void test_getField() {
    try {
        assertEquals(B.class.getField("name"), Y.class.getField("name"));
    } catch (NoSuchFieldException e) {
        fail("Got exception");
    }
}

Why does Y.class.getField("name") return B.name instead of A.name? Is there any answer in the Java specification?





Aucun commentaire:

Enregistrer un commentaire