这可能吗?
class A<T extends Service<E extends Entity>>
Run Code Online (Sandbox Code Playgroud)
这是因为我想获得服务和实体的类型.或者其他任何方式来做它?
目前我有一个设置服务的抽象方法,但如果我可以在参数中做得更好.
I'm also wondering how can I pass the parameters in a base class:
I have ClassA that extends SubBaseClass1 that extends BaseClass1.
So:
class SubBaseClass1<E extends Entity, P extends Service<E>> { }
Run Code Online (Sandbox Code Playgroud)
In BaseClass, I want to know the type of P and E.
Another question, if I have a method getBaseClass from another class, how will I specify the return type?:
public BaseClass<E extends Entity, T extends Service<E>> getBaseClass() { }
Run Code Online (Sandbox Code Playgroud)
Is not working.
Found the answer:
public BaseClass<? extends IEntity, ? extends Service<?>> getBaseClass() { }
Run Code Online (Sandbox Code Playgroud)
你会这样声明:
class A<E extends Entity, T extends Service<E>>
Run Code Online (Sandbox Code Playgroud)
然后你就可以拥有,例如:
A<Foo, Bar> a;
Run Code Online (Sandbox Code Playgroud)
... where Foo的子类是Entity和Bar的子类Service<Foo>.