I have a class with a method which I want to be accessible only for its child objects, and not for other classes in this package.
Modifier | Class | Package | Subclass | World
————————————+———————+—————————+——————————+———————
public | ✔ | ✔ | ✔ | ✔
————————————+———————+—————————+——————————+———————
protected | ✔ | ✔ | ✔ | ✘
————————————+———————+—————————+——————————+———————
no modifier | ✔ | ✔ | ✘ | ✘
————————————+———————+—————————+——————————+———————
private | ✔ | ✘ | ✘ | ✘
____________+_______+_________+__________+_______
my Modifier | ✔ | ✘ | ✔ | ✘
____________+_______+_________+__________+_______
Is there a workaround to have this kind of modifier?
Maybe there is a way to make a package final, so other programmers can not add any classes into my package?
Or is there a way to get the instance which called the function, and check whether this one is an instance of my super
object?
Or do I just have to leave it, and just use protected, and other programmers might add classes to my package...