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

Groovy class not compatible with Java integration when @Immutable is used

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.0
    • 1.8.1, 1.7.11
    • Compiler
    • None

    Description

      The following Groovy class with the UsePerson.java below works well:

      class Person {
        String firstName
        public Person(first) { firstName = first }
      }
      

      Defining a class with @Immutable annotation seems to result in compilation error when used from Java.

      Person.groovy
      @Immutable class Person {
        String firstName
      }
      
      UsePerson.java
      public class UsePerson {
        public static void main(String[] args) {
          Person person = new Person("Sam");
          System.out.println(person.getFirstName());
        }
      }
      
      >groovyc Person.groovy
      
      >ls
      Person.class	Person.groovy	UsePerson.java
      
      >javac UsePerson.java 
      UsePerson.java:3: cannot access Person
      bad class file: ./Person.class
      undeclared type variable: K
      Please remove or make sure it appears in the correct subdirectory of the classpath.
          Person person = new Person("Sam");
          ^
      1 error
      

      Attachments

        Activity

          People

            paulk Paul King
            venkats Venkat Srinivasan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: