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

type system loophole in wildcard substitution

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 5.0
    • specification
    • None
    • rc
    • generic
    • solaris_8

      The following program - due to Gilad Bracha - illustrates a loophole in the
      current specification for generics when wilcards are used. This problem
      and its solution are discussed in Viroli and Igarashi's papers, but we
      haven't yet incorporated a solution to the problem into the specification or
      its reference implementation.

      //////////////////////////////////////////////////////////
      import java.util.*;

      class SuperOfFlaw<S>{
          S s;
          S get() { return s;}
          void put(S a) { s = a;}

          SuperOfFlaw(S a) { s = a;}
      }

      class Flaw<T> extends SuperOfFlaw<List<T>> {
          List<T> fetch(){return s;}

          Flaw(T t){super(new ArrayList<T>()); s.add(t);}
      }

      class SuperOfShowFlaw {

          SuperOfFlaw<List<?>> m(){return null;}
      }


      public class ShowFlaw extends SuperOfShowFlaw {

          static Flaw<Number> fn = new Flaw<Number>(new Integer(3));

          Flaw<?> m(){return fn;}


          public static void main(String[] args) {
      SuperOfShowFlaw sosf = new ShowFlaw();
      SuperOfFlaw<List<?>> sof = sosf.m();
      List<String> ls = new ArrayList<String>();
      ls.add("Smalltalk rules!");
      sof.put(ls);
      Number n = fn.get().get(0);
          }

      }


            gbrachasunw Gilad Bracha (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: