Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6716

Cannot implement a trait via anonymous class

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.0-beta-2
    • 2.5.2
    • Compiler

    Description

      It is currently not possible to implement a trait by using anonymous classes:

      trait Foo { def foo() { 42 } }
      new Foo() {} // compiler complains
      

      The compiler message is:
      You are not allowed to extend the interface 'Foo', use implements instead

      This is not consistent with interfaces and abstract classes:

      interface Foo { def foo() }
      new Foo() { def foo() { 42 } } // this works
      

      It would be nice, for consistency reasons if no other, if traits could be extended to support this feature.

      Attachments

        Activity

          People

            paulk Paul King
            dsrkoc Dinko Srkoc
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: