publicstaticvoid testPublicSdk() { // This call should be successful as the method is accessible through the interface. int value = new InheritAbstract().methodPublicSdkNotInAbstractParent(); if (value != 42) { thrownew Error("Expected 42, got " + value);
}
}
publicstaticvoid testUnsupportedAppUsage() { // This call should throw an exception as the only accessible method is unsupportedappusage. try { new InheritAbstract().methodUnsupportedNotInAbstractParent(); thrownew Error("Expected NoSuchMethodError");
} catch (NoSuchMethodError e) { // Expected.
}
}
publicstaticvoid testNative(String library) {
System.load(library); int value = testNativeInternal(); if (value != 42) { thrownew Error("Expected 42, got " + value);
}
// Test that we consistently return we cannot access a hidden method.
// Dedupe hidden api warnings to trigger the optimization described below.
dedupeHiddenApiWarnings();
assertFalse(testAccessInternal(
InheritAbstract.class, "methodUnsupportedNotInAbstractParent", "()I")); // Access the accessible method through reflection. This will do an optimization pretending the // method is public API. try {
NotInAbstractInterface.class.getDeclaredMethod("methodUnsupportedNotInAbstractParent").
invoke(new InheritAbstract());
} catch (Exception e) { thrownew Error(e);
}
assertFalse(testAccessInternal(
InheritAbstract.class, "methodUnsupportedNotInAbstractParent", "()I"));
}
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.