java - 当类型完全匹配时,为什么我导入的 Maven 项目会抛出类型不兼容的错误?
问题描述
我正在尝试在使用 Maven public void updateCreoParams(ComponentFeat compFeat, Model model) 导入的主项目中调用此方法
但是当我将它称为 (1) 时,它会在构建 (2) (1)creoParams.updateCreoParams(compFeat, null); 时引发错误
- compFeat 属于 ComponentFeat 类型
(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);
解决方案
如果其他人遇到这个问题,那是因为 Maven。更新代码后用于包含 List 的参数需要 mvn clean,这就是为什么它在构建时不起作用但编译器没有抛出任何错误的原因。在 mvn clean 之后,一切都按预期工作
推荐阅读
- scroll - 停止滚动的 Tmux 配置
- azure-devops - VSTS WIki 使用 HTML Img 标签
- conda - GDAL/底图 w/ Anaconda Python 2.7 w/o internet 或其他 GIS 选项,如 cartopy
- git - 是否可以使用命令行在 Visual Studio Online 上创建一个空的 Git 存储库?
- java - 我们可以在 Spring Retry 中配置两个 RetryConfiguration 类吗?
- sql - 按特定日期条件过滤的 SQL 查询
- python - 如何在 asdict 中获取@property 方法?
- laravel - Laravel 多对多形式
- c# - 如何使用 mvvm 在 WPF 网格或用户控件上绑定获得焦点事件
- c# - 在 Unity 中访问网格渲染器材质元素