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

Casting 'this' from anonymous class to arbitrary interface succeeds

    Details

    • Subcomponent:
    • Introduced In Build:
      b128
    • Introduced In Version:
      9

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: