/* *Copyright(C)2015TheAndroidOpenSourceProject * *LicensedundertheApacheLicense,Version2.0(the"License"); *youmaynotusethisfileexceptincompliancewiththeLicense. *YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/ class Main implements Iface, Iface2 { publicstaticvoid main(String[] args) {
System.loadLibrary(args[0]); // Ensure we JIT compile the methods to test CHA behavior with default // methods.
ensureJitCompiled(Main.class, "callMain");
ensureJitCompiled(Main.class, "callIface");
ensureJitCompiled(Main.class, "callIface2");
System.out.println("Create Main instance");
Main m = new Main();
System.out.println("Calling functions on concrete Main");
callMain(m);
System.out.println("Calling functions on interface Iface");
callIface(m);
System.out.println("Calling functions on interface Iface2");
callIface2(m);
} publicstaticvoid callMain(Main m) {
System.out.println("Calling non-conflicting function on Main");
System.out.println(m.charge());
System.out.println("Calling conflicting function on Main"); try {
System.out.println(m.sayHi());
System.out.println("Unexpected no error Thrown on Main");
} catch (AbstractMethodError e) {
System.out.println("Unexpected AME Thrown on Main");
} catch (IncompatibleClassChangeError e) {
System.out.println("Expected ICCE Thrown on Main");
}
System.out.println("Calling non-conflicting function on Main");
System.out.println(m.charge()); return;
} publicstaticvoid callIface(Iface m) {
System.out.println("Calling non-conflicting function on Iface");
System.out.println(m.charge());
System.out.println("Calling conflicting function on Iface"); try {
System.out.println(m.sayHi());
System.out.println("Unexpected no error Thrown on Iface");
} catch (AbstractMethodError e) {
System.out.println("Unexpected AME Thrown on Iface");
} catch (IncompatibleClassChangeError e) {
System.out.println("Expected ICCE Thrown on Iface");
}
System.out.println("Calling non-conflicting function on Iface");
System.out.println(m.charge()); return;
} publicstaticvoid callIface2(Iface2 m) {
System.out.println("Calling conflicting function on Iface2"); try {
System.out.println(m.sayHi());
System.out.println("Unexpected no error Thrown on Iface2");
} catch (AbstractMethodError e) {
System.out.println("Unexpected AME Thrown on Iface2");
} catch (IncompatibleClassChangeError e) {
System.out.println("Expected ICCE Thrown on Iface2");
} return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.