简体   繁体   English

抽象方法应包含哪些参数

[英]What parameters should be in abstract method

I have one abstract Class Client and 4 children Client1 Client2 ... 我有一个抽象的Class Client和4 Client1 Client2 ...

each of this client line: 每个客户线:

    response = service.iszr(params);

where response and params depends on class 响应和参数取决于类

in Class1 this is 在Class1中,这是

Client1ResponseType response
Client1params params

now I want to add to the abstract class method: 现在我想添加到抽象类方法中:

  protected abstract void sendRequest(?? response, ?? params);

but I dont know what type should be 但我不知道应该是哪种类型

I try somethink like this: 我尝试这样的想法:

  protected abstract <I, O> void sendRequest(I input, O output);

and in children 和儿童

  @Override
  protected <Client1ResponseType, Client1params> void sendRequest(Client1ResponseType input,
      Client1params output) {
    output = service.iszrRobCtiAifo(input);
  }

but with no succes. 但没有成功。 There is compilation error. 有编译错误。 What I am doing wrong ? 我做错了什么?

I could not understand fully what actually you are trying to do. 我无法完全理解您实际上要做什么。

But some way you want to make it generic?? 但是您想以某种方式使其通用?

Try Object 尝试对象

  protected abstract void sendRequest(Object response, Object params);

you can extend this variant to other generics like Object[] 您可以将此变体扩展到其他泛型,例如Object[]

In the declaration of your abstract class you need to add this: 在抽象类的声明中,您需要添加以下内容:

    abstract class Client <I extends SOME_CLASS1, O extends SOME_CLASS2>

where SOME_CLASS1 is a subtype of your fist argument and SOME_CLASS2 is a subtype of your second argument, both can be Object if you need. 其中SOME_CLASS1是第一个参数的子类型,而SOME_CLASS2是第二个参数的子类型,如果需要,两者都可以是Object

And your abstract method goes like this: 您的抽象方法如下所示:

    protected abstract void sendRequest(I response, O params);

When you extend the class, you need to specify those types like this: 扩展类时,需要指定如下类型:

    class Client1 extends Client <Client1ResponseType, Client1params>

Please let me know if you got any problems. 如果您有任何问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM