src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
changeset 53040 6aeb6a23fb83
parent 51670 2dddc9394b49
child 53046 9b0d6ecd8e45
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Dec 18 07:33:07 2018 -0500
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Dec 18 16:22:46 2018 -0500
@@ -91,6 +91,7 @@
     final Names names;
     final boolean allowDefaultMethods;
     final boolean mapCapturesToBounds;
+    final boolean returnTypeSustitutableSameType;
     final Check chk;
     final Enter enter;
     JCDiagnostic.Factory diags;
@@ -114,6 +115,7 @@
         Source source = Source.instance(context);
         allowDefaultMethods = Feature.DEFAULT_METHODS.allowedInSource(source);
         mapCapturesToBounds = Feature.MAP_CAPTURES_TO_BOUNDS.allowedInSource(source);
+        returnTypeSustitutableSameType = Feature.RETURN_TYPE_SUBSTITUTABLE_SAME_TYPE.allowedInSource(source);
         chk = Check.instance(context);
         enter = Enter.instance(context);
         capturedName = names.fromString("<captured wildcard>");
@@ -4235,8 +4237,13 @@
             return covariantReturnType(r1.getReturnType(), r2res, warner);
         if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
             return true;
-        if (!isSubtype(r1.getReturnType(), erasure(r2res)))
-            return false;
+        if (returnTypeSustitutableSameType) {
+            if (!isSameType(r1.getReturnType(), erasure(r2res)))
+                return false;
+        } else {
+            if (!isSubtype(r1.getReturnType(), erasure(r2res)))
+                return false;
+        }
         warner.warn(LintCategory.UNCHECKED);
         return true;
     }