A class ServerServiceDefinition with generic types defined here. I’m trying to take an existing instance of this class, modify some properties and reconstruct another instance of a ServerServiceDefinition by calling the addMethod declared as
public <ReqT, RespT> Builder addMethod(
MethodDescriptor<ReqT, RespT> method, ServerCallHandler<ReqT, RespT> handler)
Below is my code
public ServerServiceDefinition bindService() {
ServerServiceDefinition serverServiceDefinitionV1 = ProtoReflectionServiceV1.newInstance()
.bindService();
MethodDescriptor<?, ?> methodDescriptorV1 = serverServiceDefinitionV1.getServiceDescriptor()
.getMethods().iterator().next(); // Because there is only 1 method in the service.
MethodDescriptor<?, ?> methodDescriptorV1Alpha = methodDescriptorV1.toBuilder()
.setFullMethodName(generateFullMethodName(SERVICE_NAME, METHOD_NAME))
.setSchemaDescriptor(
new ServerReflectionMethodDescriptorSupplier(METHOD_NAME))
.build();
ServiceDescriptor serviceDescriptorV1Alpha = ServiceDescriptor.newBuilder(SERVICE_NAME)
.setSchemaDescriptor(new ServerReflectionFileDescriptorSupplier())
.addMethod(methodDescriptorV1Alpha)
.build();
return ServerServiceDefinition.builder(serviceDescriptorV1Alpha)
.addMethod(methodDescriptorV1Alpha,
serverServiceDefinitionV1.getMethod(
generateFullMethodName(ServerReflectionGrpc.SERVICE_NAME, METHOD_NAME))
.getServerCallHandler())
.build();
}
which fails to compile on the addMethod call arguments:
error: no suitable method found for
addMethod(MethodDescriptor<CAP#1,CAP#2>,ServerCallHandler<CAP#3,CAP#4>)
.addMethod(methodDescriptorV1Alpha,
^
method Builder.<ReqT#1,RespT#1>addMethod(MethodDescriptor<ReqT#1,RespT#1>,ServerCallHandler<ReqT#1,RespT#1>)
is not applicable
(inference variable ReqT#1 has incompatible equality constraints CAP#5,CAP#1) where ReqT#1,RespT#1 are type-variables:
ReqT#1 extends Object declared in method <ReqT#1,RespT#1>addMethod(MethodDescriptor<ReqT#1,RespT#1>,ServerCallHandler<ReqT#1,RespT#1>)
RespT#1 extends Object declared in method <ReqT#1,RespT#1>addMethod(MethodDescriptor<ReqT#1,RespT#1>,ServerCallHandler<ReqT#1,RespT#1>)
where CAP#1,CAP#2,CAP#3,CAP#4,CAP#5 are fresh type-variables:
CAP#1 extends Object from capture of ?
CAP#2 extends Object from capture of ?
CAP#3 extends Object from capture of ?
CAP#4 extends Object from capture of ?
CAP#5 extends Object from capture of ?
How to resolve this?