[ https://issues.apache.org/jira/browse/GROOVY-5013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17761592#comment-17761592 ]
Eric Milles edited comment on GROOVY-5013 at 9/3/23 1:47 PM: ------------------------------------------------------------- "class SingleTest \{ ..." and "SingleTest test = new SingleTest(); test.test()" are nest mates. The implicit script class hosts both and so private access is allowed even in Java. {code:java} public class Main { public static void main(String[] args) { SingleTest test = new SingleTest(); test.test(); } static class SingleTest { private static final SingleTest Instance = new SingleTest(); private SingleTest() { } public SingleTest getInstance() { return Instance; } void test() { System.out.println("test"); } } } {code} was (Author: emilles): "class SingleTest \{ ..." and "SingleTest test = new SingleTest(); test.test()" are nest mates. The implicit script class hosts both and so private access is allowed even in Java. {code:java} public class Main { public static void main(String[] args) { SingleTest test = new SingleTest(); test.test(); } static class SingleTest { private static final SingleTest Instance = new SingleTest(); private SingleTest() { } public SingleTest getInstance() { return Instance; } void test() { System.out.println("test"); } } } {code} > Instantioantion object of class with private constructor > -------------------------------------------------------- > > Key: GROOVY-5013 > URL: https://issues.apache.org/jira/browse/GROOVY-5013 > Project: Groovy > Issue Type: Sub-task > Components: groovy-jdk > Affects Versions: 1.8.2 > Reporter: Pavel Alexeev > Priority: Major > > I have try use standard Singleton pattern in groovy script: > {code:java} > public class SingleTest { > private static final Instance = new SingleTest(); > private SingleTest(){ } > public SingleTest getInstance(){ > return Instance; > } > void test(){ > println 'test'; > } > } > SingleTest test = new SingleTest(); > test.test(); > {code} > But groovy instantiate object even if constructor marked as private: > {noformat} > D:\imus\IdeaProjects\imus\instup\src\main\java\test-private-constructor>groovy > test.groovy > test > {noformat} > P.S. Sorry for noise with http://jira.codehaus.org/browse/GROOVY-5012 I'd > expect what in cloning process I can be able change description of bug. -- This message was sent by Atlassian Jira (v8.20.10#820010)