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

Accessing private constructor from a static factory

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      The following code works fine from Java but fails in Groovy:

      public abstract class FooMain {
          private FooMain() {}
          public abstract String bar();
          public static FooMain factory() {
            return new FooMain() {
              public String bar() { return "xxx"; }
            };
          }
          public static void main(String[] args) {
              System.out.println(factory().bar());
          }
      }
      // => java.lang.IllegalAccessError: tried to access method FooMain.<init>()V from class FooMain$1
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            emilles Eric Milles
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h

                Slack

                  Issue deployment