0
假设,我加载由ClassLoader
的类别在运行时:的java:如何通过类加载器获取单个实例
Class<MyInterface> clazz = (Class<MyInterface>)getClass().getClassLoader().loadClass("ImplementerOfMyInterface");
新的实例,我可以通过
MyInterface myInt = clazz.newInstance();
创建然后但当我需要通过实现MyInterface
的名称来获取单例实例,而不是创建新实例,应该做些什么?
场有名字,但是实例没有名字。你能举一个你的意思吗? –