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

inner classes versus wildcards

XMLWordPrintable

    • generic
    • solaris_8

      Matthias Zenger wrote:
      > yesterday I was playing a little bit with your javac pre-release
      > that includes wildcards. Everything seems to work fine as long as
      > there are no inner classes involved. Here's a small example
      > that basically yields a "method not found" exception at runtime even
      > though it compiles without complaints:
      >
      > class A {
      > void a() {}
      > }
      > class B extends A {
      > void b() {}
      > }
      > class Bug<T> {
      > T elem;
      > class Inner {
      > void put(T e) {
      > elem = e;
      > }
      > }
      > public static void main(String[] args) {
      > Bug<B> b = new Bug<B>();
      > Bug<? extends A> a = b;
      > a.new Inner().put(new A()); // this should not be possible
      > b.elem.b(); // this yields a ClassCastException
      > }
      > }

            ahe Peter Ahe
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: