#inner class

1 messages · Page 1 of 1 (latest)

compact nest
#

if I have a private inner class, do I still need to make the constructor private to prevent initialization from outside?

real yachtBOT
#

<@&987246399047479336> please have a look, thanks.

real yachtBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

errant sage
#

no

compact nest
#

ok thanks :D

real yachtBOT
#

Closed the thread.

compact nest
#

if my inner class is private and it got public methods, can outside code use these methods?

#

seems like I need to make the class public for that

errant sage
#

statically, no

compact nest
#

hm

errant sage
#

unless those methods are also on a public supertype

#
public interface Apple {
    void eat();
}
public final class Tree {
    public static Apple growApple() {
        return new GrannySmith();
    }

    private class GrannySmith implements Apple {
        @Override
        public void eat() {
            System.out.println("sour");
        }
    }
}
#

like Tree.growApple().eat() will work

compact nest
#

ok thanks

errant sage
#

im not really sure what is and isn't reflectively accessible