簡體   English   中英

具有多個泛型類型的Java編譯器錯誤

[英]Java Compiler error with multiple generics type

我有這樣的界面:

public interface GenericWSEndpoint<T1,T2> {

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

}

當我嘗試用這個來定義一個對象時,它給出了

org.apache.maven.BuildFailureException:編譯失敗:不兼容的類型

對象定義:

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>{
.
.
}

我已經檢查了有關此問題的答案,但它們與遞歸泛型等定義有關

有任何想法嗎?

編輯:例外:

[INFO]編譯失敗ResponseManager \\ src \\ main \\ java \\ com \\ x \\ resman \\ util \\ WebServiceUtil.java:[57,142]不兼容的類型; 沒有類型變量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>

嘗試使用以下代碼:

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

代替

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

您是否在Maven POM文件中指定了Java源代碼版本? 目前,默認情況下Maven使用1.5。 你可能需要更新的東西。 您在我們的IDE中使用的是哪個版本?

相關的Maven配置是:

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

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM