简体   繁体   English

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

[英]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 org.apache.maven.BuildFailureException:编译失败:不兼容的类型

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): 和CXFWsEndPoint(没有具体定义的构造函数):

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; [INFO]编译失败ResponseManager \\ src \\ main \\ java \\ com \\ x \\ resman \\ util \\ WebServiceUtil.java:[57,142]不兼容的类型; 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: 没有类型变量T1,T2的实例存在,以便com.x.rbm.ws.service.GenericWSEndpoint符合com.x.rbm.ws.service.GenericWSEndpoint found:com.x.rbm.ws .service.GenericWSEndpoint必需:

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

Try with the following code: 尝试使用以下代码:

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

instead of 代替

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

Are you specifying the Java source version in your Maven POM file? 您是否在Maven POM文件中指定了Java源代码版本? Currently, by default Maven uses 1.5. 目前,默认情况下Maven使用1.5。 You probably need something more recent. 你可能需要更新的东西。 What version are you using in our IDE? 您在我们的IDE中使用的是哪个版本?

The relevant Maven configuration is: 相关的Maven配置是:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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