mercredi 12 août 2015

Class#getDeclaredMethods() returns inherited methods as 'default'

Consider next code:

interface A {
    A setX(Object x);
    A setY(Object y);
}

interface B extends A {
    B setX(Object x);
}

If you try to use B.class.getDeclaredMethods() with jdk8 you will get next methods:

public abstract B B.setX(java.lang.Object) and public default A B.setX(java.lang.Object)

Javadoc says that Class#getDeclaredMethods() returns only DECLARED methods so why 2 methods are returned? And if someone has explanation then why do second method has 'default' modifier?

Should i post a bugreport? This issue is pretty close to this one but affected version is jdk6 and for jdk7 it works fine(returns single method)





Aucun commentaire:

Enregistrer un commentaire