javagenerics

Java Compiler error with multiple generics type


I have a interface like this:

public interface GenericWSEndpoint<T1,T2> {

    public void call(String url,String operationName, T1 requestObject, T2 responseObject,long timeout) throws Exception;

}

When I try to define an object with this, it gives

org.apache.maven.BuildFailureException: Compilation failure : incompatible types

Object definition:

private static GenericWSEndpoint<BulkCheckBlockageRequest,BulkCheckBlockageResponse> endpoint=GenericWsEndpointFactory.createSpecificEndpoint(WSTypes.CXF);

And factory code:

public class GenericWsEndpointFactory{

    public static <T1,T2> GenericWSEndpoint createSpecificEndpoint(WSTypes type){
        switch (type) {
        case CXF:

            return new CXFWsEndPoint<T1,T2>();
        }

        return null;
    }

}

and the CXFWsEndPoint(no constructors defined specificly):

public class CXFWsEndPoint<T1,T2> implements GenericWSEndpoint<T1, T2>{
.
.
}

I have checked the answers about this problem but they are related with definitions like recursive generics

Any ideas?

EDIT: Exception:

[INFO] Compilation failure ResponseManager\src\main\java\com\x\resman\util\WebServiceUtil.java:[57,142] incompatible types; no instance(s) of type variable(s) T1,T2 exist so that com.x.rbm.ws.service.GenericWSEndpoint conforms to com.x.rbm.ws.service.GenericWSEndpoint found : com.x.rbm.ws.service.GenericWSEndpoint required:

com.x.rbm.ws.service.GenericWSEndpointequest,com.x.resman.model.checkblockage.BulkCheckBlockageResponse>


Solution

  • Try with the following code:

      public static <T1, T2> GenericWSEndpoint<T1, T2> createSpecificEndpoint() {
    

    instead of

      public static <T1, T2> GenericWSEndpoint createSpecificEndpoint() {