I wonder if modern JVM would optimize a non-extended private class as
final... or if there always a chance that a subclass can appear.

Gary

On Sat, Nov 18, 2023, 10:14 AM Gary Gregory <garydgreg...@gmail.com> wrote:

> On Sat, Nov 18, 2023 at 10:02 AM Alex Herbert <alex.d.herb...@gmail.com>
> wrote:
> >
> > On Sat, 18 Nov 2023 at 12:49, Gary Gregory <garydgreg...@gmail.com>
> wrote:
> > >
> > > On Sat, Nov 18, 2023 at 3:36 AM Alex Herbert <alex.d.herb...@gmail.com>
> wrote:
> > > >
> > > > Installed from the maven tag.
> > > >
> > > > Built lang and statistics using JDK 8 and 11:
> > > >
> > > > Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9)
> > > > Maven home: /Users/ah403/mvn/mvn
> > > > Java version: 1.8.0_362, vendor: Temurin, runtime:
> > > > /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/jre
> > > > Default locale: en_GB, platform encoding: UTF-8
> > > > OS name: "mac os x", version: "13.4.1", arch: "x86_64", family: "mac"
> > > >
> > > > Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9)
> > > > Maven home: /Users/ah403/mvn/mvn
> > > > Java version: 11.0.18, vendor: Eclipse Adoptium, runtime:
> > > > /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
> > > > Default locale: en_GB, platform encoding: UTF-8
> > > > OS name: "mac os x", version: "13.4.1", arch: "aarch64", family:
> "mac"
> > > >
> > > > lang:
> > > > Fails on SpotBugs with 9 errors. Rerunning with -Dspotbugs.skip
> works.
> > > > I did not fix the source.
> > > >
> > > > statistics:
> > > > Fails on SpotBugs with 1 error in the inference module. Fixed in the
> source.
> > > > Fails on checkstyle under JDK 11 with errors due to private final
> > > > classes not declared as final. This is a strange one as IIRC other
> > > > tools state that the keyword is redundant. I have corrected in source
> > > > for now.
> > >
> > > The keyword cannot be redundant, otherwise, this would not work:
> > >
> > > public class Root {
> > >
> > >     private static class SP1 {
> > >     }
> > >
> > >     private static class SP2 extends SP1 {
> > >     }
> > >
> > >     private class P1 {
> > >     }
> > >
> > >     private class P2 extends P1 {
> > >     }
> > > }
> > >
> > > Or am I missing something?
> >
> > The fact that it is private means that the final keyword to prevent
> > extension by others is mute. It does of course prevent extension by
> > yourself. But since you control the source then you can add or drop it
> > as desired. It makes no difference to downstream consumers of the
> > class.
>
> Well, sure, but that does not change the fact that the class is not
> final by default as far as Java bytes codes are concerned.
>
> Gary
> >
> > Alex
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> > For additional commands, e-mail: dev-h...@commons.apache.org
> >
>

Reply via email to