首页 > 解决方案 > 当类型完全匹配时,为什么我导入的 Maven 项目会抛出类型不兼容的错误?

问题描述

我正在尝试在使用 Maven public void updateCreoParams(ComponentFeat compFeat, Model model) 导入的主项目中调用此方法

但是当我将它称为 (1) 时,它会在构建 (2) (1)creoParams.updateCreoParams(compFeat, null); 时引发错误

(2)Error:(216, 61) java: incompatible types: com.ptc.pfc.pfcComponentFeat.ComponentFeat 无法转换为 java.util.List<[package].Parameter>

List 是在构造函数中为类设置的变量,如果这有所不同的话。任何帮助,将不胜感激。谢谢你

更新

这是导致问题的类。我希望它能够工作,但由于某种原因,上面的错误会在构建时引发,即使被调用的方法没有将 List 作为参数

public class CreoParameters {
    ArrayList<String> parameterList;
    List<Parameter> params;
    /**
     * Initialize this object with a list of parameters that you want to put onto the model
     * @param params
     */
    public CreoParameters(List<Parameter> params){
        this.params = params;
        parameterList = new ArrayList<String>();
        for(int i=0; i<params.size(); i++){
            parameterList.add(params.get(i).parameterName);
        }
    }

    /**
     * Updates the Parameters in Creo for a given assembly component, and a list of Params
     * @param compFeat
     * @param model
     * @author jcesson
     */
    public void updateCreoParams(ComponentFeat compFeat, Model model) {
        try {
            ParameterOwner modelToUpdate;
            if(compFeat != null) {
                modelToUpdate = compFeat;
            }else if(model != null){
                modelToUpdate = model;
            }else{
                modelToUpdate = null;
                return;
            }
            //Removes old instance of Parameters to be updated
            Parameters oldParams = modelToUpdate.ListParams();
            for(int i=0; i<oldParams.getarraysize(); i++) {
                String oldParamName = oldParams.get(i).GetName();
                if(parameterList.contains(oldParamName)) {
                    oldParams.get(i).Delete();
                }
            }
            oldParams.clear();

            //Adds in the new Parameters
            for(int i=0; i<params.size(); i++) {
                ParamValue newPV = pfcModelItem.CreateStringParamValue(params.get(i).getParameterValue());
                modelToUpdate.CreateParam(params.get(i).getParameterName(), newPV);
            }

        } catch (jxthrowable e) {

            CEWSLogger.info("Bad Creo Model Error "+e.toString());

        }
        
    }
}

这就是它的调用方式,并且在构建时抛出错误的地方 updatedParams 或 compFeat 都不是空的。

private List<Parameter> updatedParams = new ArrayList<Parameter>();
private ComponentFeat compFeat;
.
.
.
CreoParameters creoParams = new CreoParameters(updatedParams);
creoParams.updateCreoParams(compFeat, null);

标签: javamaven

解决方案


如果其他人遇到这个问题,那是因为 Maven。更新代码后用于包含 List 的参数需要 mvn clean,这就是为什么它在构建时不起作用但编译器没有抛出任何错误的原因。在 mvn clean 之后,一切都按预期工作


推荐阅读