-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further fixes for #904 -- java8 generates
default methods for subclasses when they override generic methods with the more specific type. We use a two-tiered approach to fixing: (1) try to use MethodHandles + unreflectSpecial, which lets us call default method implementations directly, and if that doesn't work then (2) try to map default methods to compatible method signatures that could be the overrides of the method. (1) may not always work because we're using a private API [new Lookup(clazz, int)], but we need to do that in order to non-public classes. (2) may not always work because it's possible to have more than one compatible method signature. In the unlikely case that both (1) & (2) fail, we give an error message. Also: we must validate the default method's return type for visibility vs the factory type's visibility too. This ends up with two possible differences caused by java8: a) If the Lookup cxtor can't be used (different JDK, version skew, etc..) and there's more than one compatible method signature: we fail. b) If the default method's return type isn't public but the factory is public: we fail. For reference, javac8 generates a default method in the following scenario: interface Parent<I extends CharSequence, O extends Number> { O create(I input); } interface Child<String, Integer> { Integer create(String input); } Child has a generated default method of: Number create(CharSequence input); ... so, for example, failure could be newly triggered if 'Number' was package-private but Child was public, or if the reflection APIs didn't work and Child also had a 'Integer create(StringBuilder input);' method. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=87097207
- Loading branch information
Showing
2 changed files
with
243 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters