Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何保护在另一个包中使用的类(来自不继承的类)从外部实例化?这在Java中甚至可能吗?
使构造函数受保护
public class ProtectClass { protected ProtectClass() { // TODO Auto-generated constructor stub } }
好吧,抽象类不能被实例化,但这可能不是你要找的……我从来没有听说过这是可能的。