多个泛型类型的 Java 编译器错误

标签 java generics compiler-construction

我有一个这样的界面:

public interface GenericWSEndpoint<T1,T2> {

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

}

当我尝试用它定义一个对象时,它给出

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

对象定义:

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

和工厂代码:

public class GenericWsEndpointFactory{

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

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

        return null;
    }

}

和 CXFWsEndPoint(没有具体定义的构造函数):

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

我已经检查了有关此问题的答案,但它们与递归泛型等定义有关

有什么想法吗?

编辑:异常(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>

最佳答案

尝试使用以下代码:

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

而不是

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

关于多个泛型类型的 Java 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17521982/

相关文章:

c++ - 对于 { A=a;乙=乙; }, "A=a"会在 "B=b"之前严格执行吗?

java - 七月到 TomEE 1.7.2 上的 SLF4J,带有 Maven 插件

java - 理解对象(Java)有点困难

java - 使用 GWT JNSI 从 Javascript 调用 Java

c# - 从 'V'到 'System.IEquatable<V>'没有装箱转换或者类型参数转换

c# - 使用反射创建通用委托(delegate)

c编译器类型检查算法和语义分析

生成 .exe 文件的 Java 编译器选项

java - Hibernate 没有删除我的对象。为什么?

c# - 比较 IEnumerable<T> 的类型