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

ConfigObject instance can't be coerced into trait in runtime

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.0
    • None
    • Compiler

    Description

      It works with other classes, even Java (Integer for example):

      trait Extra {
          String extra() { "I'm an extra method" }
      }
      class Something {
          String doSomething() { 'Something' }
      }
      
      def s = new Something() as Extra;
      assert "I'm an extra method" == s.extra()
      assert 'Something' == s.doSomething()
      
      def i = new Integer(0) as Extra;
      assert "I'm an extra method" == i.extra()
      
      def conf = new ConfigSlurper().parse('some = 7')
      // Uncomment it and you are receive error:
      // def ss = conf as Extra
      /*
      java.lang.NoClassDefFoundError: Extra
          at ConsoleScript24.run(ConsoleScript24:16)
      Caused by: java.lang.ClassNotFoundException: Extra
          ... 1 more
      */
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            hubbitus Pavel Alexeev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: