从父引用调用子类的方法

Call method of subclass from parent reference

我有 3 个 OSGi 包,例如实现的 class 名称相同但在不同的包中:

Bundle A (com.adobe) ---- Interface ( foo() )
Bundle B (org.custom) ---- ChildClassA ( foo() {} )
Bundle C (myprj.adobe) ---- ChildClassA ( foo() {} )

我有一个片段如下:

Interface refObj;
refObj.foo();

如何从另一个包中注入特定实现的对象 class。

谢谢,

如果您有实现相同接口的不同服务,那么您可以add properties to the services

在客户端,您可以使用带有目标的引用。

@Reference(target="(key=value)")

此引用仅匹配具有 属性 "key" 且值为 "value".

的服务