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

Casting 'this' from anonymous class to arbitrary interface succeeds

XMLWordPrintable

    • b128
    • 9

      Let's consider following code:

      interface I {}

      class Test {
          void foo() {
              new Object() {
                  I bar() {
                      return (I)this;
                  }
              };
          }
      }

      This code compiles successfully by javac from JDK build 128. However compilation should fail on 'return (I)this;' because the anonymous class doesn't have any relation to interface I.

            dlsmith Dan Smith
            grakov Georgiy Rakov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: