简体   繁体   中英

What parameters should be in abstract method

I have one abstract Class Client and 4 children Client1 Client2 ...

each of this client line:

    response = service.iszr(params);

where response and params depends on class

in Class1 this is

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[]

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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