Answer the question
In order to leave comments, you need to log in
Is it possible to use generic like C++ templates?
Is it possible to do something like this:
private LongPollServer initServer (Resp1 r) .....
private LongPollServer initServer (Resp2 r) .....
private LongPollServer initServer (Resp3 r) .....
protected <R> void run (ApiRequest<R> req)
{
.....
LongPollServer lps = initServer((R)req.exec());
.....
}
Answer the question
In order to leave comments, you need to log in
In the end I wrote this:
private LongPollServer initServer (Object lpServerResponse) {
if (lpServerResponse instanceof GetLongPollServerResponse)
return new LongPollServer()
.setKey(((GetLongPollServerResponse)lpServerResponse).getKey())
.setTs(((GetLongPollServerResponse)lpServerResponse).getTs())
.setServer(((GetLongPollServerResponse)lpServerResponse).getServer());
else if (lpServerResponse instanceof com.vk.api.sdk.objects.messages.responses.GetLongPollServerResponse)
return new LongPollServer()
.setKey(((com.vk.api.sdk.objects.messages.responses.GetLongPollServerResponse)lpServerResponse).getKey())
.setTs(((com.vk.api.sdk.objects.messages.responses.GetLongPollServerResponse)lpServerResponse).getTs().toString())
.setServer(((com.vk.api.sdk.objects.messages.responses.GetLongPollServerResponse)lpServerResponse).getServer());
else
return new LongPollServer()
.setKey(((com.vk.api.sdk.objects.callback.longpoll.responses.GetLongPollServerResponse)lpServerResponse).getKey())
.setTs(((com.vk.api.sdk.objects.callback.longpoll.responses.GetLongPollServerResponse)lpServerResponse).getTs())
.setServer(((com.vk.api.sdk.objects.callback.longpoll.responses.GetLongPollServerResponse)lpServerResponse).getServer());
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question