src/share/classes/com/sun/tools/javac/code/Types.java

changeset 202
3b2c55b7bd01
parent 196
1ca2dc8584e1
child 210
1aa81917016a
equal deleted inserted replaced
201:e3930187199c 202:3b2c55b7bd01
2931 * Return-Type-Substitutable. 2931 * Return-Type-Substitutable.
2932 * @see <a href="http://java.sun.com/docs/books/jls/">The Java 2932 * @see <a href="http://java.sun.com/docs/books/jls/">The Java
2933 * Language Specification, Third Ed. (8.4.5)</a> 2933 * Language Specification, Third Ed. (8.4.5)</a>
2934 */ 2934 */
2935 public boolean returnTypeSubstitutable(Type r1, Type r2) { 2935 public boolean returnTypeSubstitutable(Type r1, Type r2) {
2936 return returnTypeSubstitutable(r1, r2, Warner.noWarnings);
2937 }
2938 //where
2939 public boolean returnTypeSubstitutable(Type r1, Type r2, Warner warner) {
2940 if (hasSameArgs(r1, r2)) 2936 if (hasSameArgs(r1, r2))
2941 return resultSubtype(r1, r2, warner); 2937 return resultSubtype(r1, r2, Warner.noWarnings);
2942 else 2938 else
2943 return covariantReturnType(r1.getReturnType(), 2939 return covariantReturnType(r1.getReturnType(),
2944 r2.getReturnType(), 2940 erasure(r2.getReturnType()),
2945 warner); 2941 Warner.noWarnings);
2942 }
2943
2944 public boolean returnTypeSubstitutable(Type r1,
2945 Type r2, Type r2res,
2946 Warner warner) {
2947 if (isSameType(r1.getReturnType(), r2res))
2948 return true;
2949 if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
2950 return false;
2951
2952 if (hasSameArgs(r1, r2))
2953 return covariantReturnType(r1.getReturnType(), r2res, warner);
2954 if (!source.allowCovariantReturns())
2955 return false;
2956 if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
2957 return true;
2958 if (!isSubtype(r1.getReturnType(), erasure(r2res)))
2959 return false;
2960 warner.warnUnchecked();
2961 return true;
2946 } 2962 }
2947 2963
2948 /** 2964 /**
2949 * Is t an appropriate return type in an overrider for a 2965 * Is t an appropriate return type in an overrider for a
2950 * method that returns s? 2966 * method that returns s?
2951 */ 2967 */
2952 public boolean covariantReturnType(Type t, Type s, Warner warner) { 2968 public boolean covariantReturnType(Type t, Type s, Warner warner) {
2953 //are return types identical? 2969 return
2954 if (isSameType(t, s)) 2970 isSameType(t, s) ||
2955 return true; 2971 source.allowCovariantReturns() &&
2956 //if t and s are both reference types...
2957 else if(source.allowCovariantReturns() &&
2958 !t.isPrimitive() && 2972 !t.isPrimitive() &&
2959 !s.isPrimitive()) { 2973 !s.isPrimitive() &&
2960 //check that t is some unchecked subtype of s 2974 isAssignable(t, s, warner);
2961 if (isSubtypeUnchecked(t, s, warner))
2962 return true;
2963 //otherwise check that t = |s|
2964 else if (isSameType(t, erasure(s))) {
2965 warner.warnUnchecked();
2966 return true;
2967 }
2968 }
2969 //otherwise t is not return type substitutable for s
2970 return false;
2971 } 2975 }
2972 // </editor-fold> 2976 // </editor-fold>
2973 2977
2974 // <editor-fold defaultstate="collapsed" desc="Box/unbox support"> 2978 // <editor-fold defaultstate="collapsed" desc="Box/unbox support">
2975 /** 2979 /**

mercurial