Thanks for the clarification, Paul!

--blake





On Fri, Sep 27, 2024 at 10:27 PM Paul King <pa...@asert.com.au> wrote:

> In terms of generated bytecode, Java and Groovy are the same with the
> following exceptions:
> * for methods and classes, Groovy defaults to public visibility if you
> provide no visibility modifier (that is what Intellij is telling you)
> * for fields, Groovy turns a field into a property if there is no
> visibility modifier
> * Java defaults to package-private visibility, you have to use
> @PackagePrivate in Groovy for this rarer case
>
> In terms of obeying scoping, both Java and Groovy let you get to
> private members through reflection in earlier JDKs. Groovy provides
> nicer syntax for this when using dynamic mode but you shouldn't rely
> on that since it has been essentially turned off for later JDKs.
>
> Cheers, Paul.
>
> On Sat, Sep 28, 2024 at 5:04 AM Blake McBride <blake1...@gmail.com> wrote:
> >
> > Greetings,
> >
> > Although I have been using Groovy for years, I have largely been
> ignoring scoping as it relates to classes, methods, and fields.  It is my
> opinion that having private and package-level scoping is critical.
> Controlling scope is critical to managing a large project.
> >
> > The way I've been ignoring the issue is:
> >
> > 1. I just assume it's the same as Java and treat it that way.
> >
> > 2. Since my large project (~9,000 classes) is broken down into small
> packages, I also control visibility by not cross-accessing packages.
> >
> > (I understand the field property bit.)
> >
> > My problem is because of two factors:
> >
> > 1. The documentation that comes with Groovy is not explicit about this.
> >
> > 2. My IDE (IntelliJ) grays out "public" trying to tell me it isn't
> needed.
> >
> > So, I'd like to get a clear explanation of scope control for classes,
> methods, and fields.
> >
> > Thanks!
> >
> > Blake McBride
> >
> >
> >
>

Reply via email to