mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 12:09:14 +00:00
Only resolve object methods on interfaces
This commit is contained in:
parent
6ce63a4a5b
commit
e6c4855a93
@ -702,12 +702,14 @@ public class LambdaToMethod extends TreeTranslator {
|
||||
String functionalInterfaceClass = classSig(targetType);
|
||||
String functionalInterfaceMethodName = samSym.getSimpleName().toString();
|
||||
String functionalInterfaceMethodSignature = typeSig(types.erasure(samSym.type));
|
||||
Symbol baseMethod = types.overriddenObjectMethod(refSym.enclClass(), refSym);
|
||||
if (baseMethod != null) {
|
||||
// The implementation method is a java.lang.Object method, runtime will resolve this method to
|
||||
// a java.lang.Object method, so do the same.
|
||||
// This case can be removed if JDK-8172817 is fixed.
|
||||
refSym = ((MethodSymbol) baseMethod).asHandle();
|
||||
if (refSym.enclClass().isInterface()) {
|
||||
Symbol baseMethod = types.overriddenObjectMethod(refSym.enclClass(), refSym);
|
||||
if (baseMethod != null) {
|
||||
// The implementation method is a java.lang.Object method, runtime will resolve this method to
|
||||
// a java.lang.Object method, so do the same.
|
||||
// This case can be removed if JDK-8172817 is fixed.
|
||||
refSym = ((MethodSymbol) baseMethod).asHandle();
|
||||
}
|
||||
}
|
||||
String implClass = classSig(types.erasure(refSym.owner.type));
|
||||
String implMethodName = refSym.getQualifiedName().toString();
|
||||
|
||||
@ -63,9 +63,15 @@ public class SerializableObjectMethodReferencesOnInterfaces {
|
||||
R apply(T t);
|
||||
}
|
||||
|
||||
enum E {
|
||||
ONE
|
||||
}
|
||||
|
||||
void f() throws Exception {
|
||||
F<I1, Integer> f1 = I1::hashCode;
|
||||
F<I2, Integer> f2 = I2::hashCode;
|
||||
F<E, Integer> f3 = E::hashCode;
|
||||
F<Object, Integer> f4 = Object::hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,6 +97,18 @@ public class SerializableObjectMethodReferencesOnInterfaces {
|
||||
getFunctionalInterfaceMethodSignature (Ljava/lang/Object;)Ljava/lang/Object;
|
||||
getImplClass java/lang/Object
|
||||
getImplMethodSignature ()I
|
||||
getImplMethodKind 5
|
||||
getFunctionalInterfaceClass SerializableObjectMethodReferencesOnInterfaces$Test$F
|
||||
getFunctionalInterfaceMethodName apply
|
||||
getFunctionalInterfaceMethodSignature (Ljava/lang/Object;)Ljava/lang/Object;
|
||||
getImplClass java/lang/Enum
|
||||
getImplMethodSignature ()I
|
||||
getImplMethodKind 5
|
||||
getFunctionalInterfaceClass SerializableObjectMethodReferencesOnInterfaces$Test$F
|
||||
getFunctionalInterfaceMethodName apply
|
||||
getFunctionalInterfaceMethodSignature (Ljava/lang/Object;)Ljava/lang/Object;
|
||||
getImplClass java/lang/Object
|
||||
getImplMethodSignature ()I
|
||||
""";
|
||||
if (!actual.equals(expected)) {
|
||||
throw new AssertionError(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user