I have the A class in the a package.
After I have the B class in the a.b package. B contains the method m().
I want to call m() inside and only inside class A. Precisely I don’t want to set m() to be public.
Is it possible?
Sorry for the title. I’ve not found anything better.
Edit for clarify: A and B classes have to be used by a developer (they form an API) and inside A I have a private method that compute something that modify the B object, but this cannot be called by the developer. There is any other relation between the a and a.b packages in addition to the fact that their corresponding folders are one inside the other?
Edit2: class A contains a List<B>. A is the class that has to talk with the server, which responses with a value. A has to insert this value in every element in the list.
Unless
AsubclassesB(and I wouldn’t do that just for the sake of inheritance), there’s basically no “special” relationship betweenAandB, so there’s no way of doing this, I’m afraid.What exactly do you need to protect against here? Is it just a matter of not trusting yourself or your colleagues not to call the method at the right time, or something stronger? You could potentially check the stack at execution time, although that’s dangerous in terms of inlining etc potentially messing things up – and it would only be at execution time.