我很清楚oop的多态性和继承概念,但是我处于需要知道实现类的情况。例如:如何检索父接口的实现类/接口?
public CommonReadRepository<?> getReadRepository(String tableName) {
if (tableName == null)
return null;
switch (tableName) {
case "order":
return orderRepository;
...
}
return null;
}
接口orderRepository
扩展CommonReadRepository
,而且由于我的要求,我需要访问orderRepository定义的函数。
CommonReadRepository<?> repository=getReadRepository("order");
有什么办法来检查执行(子)类或接口CommonReadRepository
?
当然,我总是可以做这样的事情:
if(tableName=="order")
return (OrderRepository)CommonReadRepository<?>;
我试着调试getReadRepository("order")
,但它给我的JdkDynamicAopProxy
的情况下,我不知道它是如何工作的。
如果(接口的instanceof XYZ类) 我不想使用它,因为我有类100,我想保持它作为最后的手段...或者换句话说 我不知道XYZ类
感谢
我真的不知道你是什么'请问......你不能使用'''instanceof'''或'''getClass()'''? –
如果您需要访问该方法,则应使用包含它的参数类型。这听起来像是一个设计问题。 – chrylis