getDeclaredMethods() behaving differently in Java 7 vs. Java 8 -
consider following little example:
package prv.rli.codetest; import java.lang.reflect.method; public class breakinginterfaces { interface base { basefoo foo(); interface basefoo { } } interface derived extends base { derivedfoo foo(); interface derivedfoo extends basefoo { } } public static void main(string[] args) { dumpdeclaredmethods(derived.class); } private static void dumpdeclaredmethods(class<?> class1) { system.out.println("---" + class1.getsimplename() + "---"); method[] methods = class1.getdeclaredmethods(); (method method : methods) { system.out.println(method); } system.out.println("----------"); } }
if compile above example jdk1.7.0.55 output is:
---derived--- public abstract breakinginterfaces$derived$derivedfoo breakinginterfaces$derived.foo() ----------
but when using jdk1.8.0.25 output is:
---derived--- public abstract prv.rli.codetest.breakinginterfaces$derived$derivedfoo prv.rli.codetest.breakinginterfaces$derived.foo() public default prv.rli.codetest.breakinginterfaces$base$basefoo prv.rli.codetest.breakinginterfaces$derived.foo() ----------
does know, whether bug in jdk1.8.0.25 or why public default method resurfaces here?
getdeclaredmethods()
behaves correctly here tells has found in class. if feed in interface
compiled java 7 target (or older compiler) see no difference output of java 7 implementation of getdeclaredmethods()
.
it’s compiler behaves differently. when compiling such sub-interface
in java 8, bridge method generated not generated java 7 target not possible java 7 target.
the reason why bridge methods generated interfaces have more implementation classes interfaces, therefore having default
bridge method in interface saves adding bridge method every implementation. further, makes lambda class generation easier if there 1 abstract
method , no bridge method implement.
when interface
hierarchy requires bridge methods provides no default
s, compiler has generate code using lambdametafactory.altmetafactory
rather lambdametafactory.metafactory
specifying every bridge method required.
Comments
Post a Comment