jeudi 27 avril 2017

Why doesn't my interface have the methods the JLS says it declares?

Reading this part in JLS:

If an interface has no direct superinterfaces, then the interface implicitly declares a public abstract member method m with signature s, return type r, and throws clause t corresponding to each public instance method m with signature s, return type r, and throws clause t declared in Object, unless a method with the same signature, same return type, and a compatible throws clause is explicitly declared by the interface.

I tried to confirm the existence of these methods through reflection, but only the ok method shows up.

Why aren't the implicitly declared methods showing up? How can I see them?

interface C {
    public void ok();
}
public class Test{
    public static void main(String[] args) {
        for (Method m : C.class.getMethods()) {
            System.out.println(m.getName()+":"+Modifier.isAbstract(m.getModifiers()));
        }
    }
}

Output:

ok:true





Aucun commentaire:

Enregistrer un commentaire