Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6371674

inference: Inferred types' bounds should help infer unconstrained type variables

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P5 P5
    • None
    • 5.0
    • specification
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.5.0_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      Invalid generics code does compiles under certain conditions

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile the code given.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code should not compile
      ACTUAL -
      The code compiles

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package tests;

      import java.util.Collection;
      import java.util.Collections;

      public class CompileTest1 {

      class Request<R extends Request<R, V>,V> {}

      class RequestMap {
      public <R extends Request<R, W>,W> R intersection (Collection<R> c) {
      // In my real code I make use of W of course
      return null;
      }
      }

      class DeltaRequest extends Request<DeltaRequest,double[]> {}

      public void test () {
      RequestMap m = new RequestMap ();
      Collection<DeltaRequest> c = Collections.singleton (new DeltaRequest ());
      // Why does this line compile?
      DeltaRequest o = m.intersection (c);
      }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Err ...

            abuckley Alex Buckley
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: