限制子类中的函数调用
我有一个基类 Base 以及从中派生的类,例如 DerivedA、DerivedB 等。并且我有从 android.os.AsyncTask 派生的任务类,例如 TaskA、Task B、TaskC 等。
我想要完成的是限制调用任务类到特定的派生类。例如
TaskA可以从DerivedA调用函数,但不能从DerivedB、DerivedC等调用函数...
I have a base class Base, and derived classes from it such as DerivedA, DerivedB etc. And I have task classes derived from android.os.AsyncTask such as TaskA, Task B, TaskC etc.
What I want to accomplish is restricting calls in Task classes to specific Derived classes. Such as
TaskA can call functions from DerivedA, but not from DerivedB,DerivedC etc ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个类都可以调用
public
方法。您可以通过将类放在单独的包中并使用包私有访问来限制访问。如果您还不知道,请参阅此处。Every class can call
public
methods. You could restrict access by putting your classes in separate packages and use package-private access. See here if you don't know it already.