Groovy equivalent Java declaration without access modifier

So, I can declare a class in Groovy as:

//groovy-code class Person { } 

which is equivalent to writing in java, for example:

 //java-code public class Person { } 

Just out of curiosity .. that Groovy is equivalent to this encoded in java:

 //java-code class Person { } 

I mean, is there a way to achieve what I can achieve in Java by declaring something without an access modifier?

+6
source share
1 answer

Since the default access modifier for a class in Java is a “closed package”, I think that the closest thing to what you could get in Groovy the same behavior would be to make the class a “protected package” that will execute with annotation @PackageScope :

 @PackageScope class Person { } 

By the way, there is an open and unresolved error (function?) In Groovy that prevents the visibility of "private" from working. An implementation is planned for Groovy v3.0.

+9
source

Source: https://habr.com/ru/post/970330/


All Articles