Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide a public method?

I have a method in my static state machine that is only used once when my application is first fired up. The method needs to be public, but I still want it hidden. Is there a way to use an annotation or something that will hide the method from the rest of the project?

like image 380
ahodder Avatar asked Feb 22 '26 09:02

ahodder


1 Answers

You cannot make a public method hidden (unless you can declare it private). You can however put in a subclass and only let the users of the object know the type of the superclass, that is:

class A {
   //Externally visible members
}

class B extends A {
   //Secret public members
}

Then you instantiate the class B, but only let the type A be known to others...

like image 139
Mathias Schwarz Avatar answered Feb 27 '26 09:02

Mathias Schwarz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!