首页 > 解决方案 > 为什么类名与导入语句中使用的类相同

问题描述

下面的代码片段来自 ITDIAgentException.java 文件

有人可以帮我理解“为什么类名与导入语句中使用的类相同”(ITDIAgentException)

import com.ibm.di.entry.Entry;
import com.ibm.di.exception.ITDIAgentException;

public class ITDIAgentException extends Exception {
  private Entry entry = null;
  
  public ITDIAgentException(String paramString) { super(paramString); }
  
  public Entry getEntry() { return this.entry; }
  
  public void setEntry(Entry paramEntry) { this.entry = paramEntry; }
}

编辑

在此处输入图像描述

标签: java

解决方案


您有两次 ITDIAgentException:一次在 import 语句中,一次在类定义中。您不能同时拥有这两者(将在代码中创建命名空间冲突),但您可以使用完整包访问 com.ibm.di.exception.ITDIAgentException(假设它与您正在创建的类不同)和班级名称。

import com.ibm.di.exception.ITDIAgentException;

public class ITDIAgentException extends Exception {

推荐阅读