Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Eclipse中找不到继承的方法_Java_Eclipse_Inheritance - Fatal编程技术网

Java 在Eclipse中找不到继承的方法

Java 在Eclipse中找不到继承的方法,java,eclipse,inheritance,Java,Eclipse,Inheritance,我正在对java代码进行语义分析。部分课程如下: ClassOrInterfaceDeclaration -> TypeDeclaration -> BodyDeclaration -> Node public final class ClassOrInterfaceDeclaration extends TypeDeclaration { private final List<AnnotationExpr> annotations; private fina

我正在对java代码进行语义分析。部分课程如下:

ClassOrInterfaceDeclaration -> TypeDeclaration -> BodyDeclaration -> Node
public final class ClassOrInterfaceDeclaration extends TypeDeclaration {

private final List<AnnotationExpr> annotations;

private final boolean isInterface;

private final List<TypeParameter> typeParameters;

private final List<ClassOrInterfaceType> extendsList;

private final List<ClassOrInterfaceType> implementsList;

public ClassOrInterfaceDeclaration(int line, int column, JavadocComment javaDoc, int modifiers, List<AnnotationExpr> annotations, boolean isInterface, String name, List<TypeParameter> typeParameters, List<ClassOrInterfaceType> extendsList, List<ClassOrInterfaceType> implementsList, List<BodyDeclaration> members) {
    super(line, column, javaDoc, name, modifiers, members);
    this.annotations = annotations;
    this.isInterface = isInterface;
    this.typeParameters = typeParameters;
    this.extendsList = extendsList;
    this.implementsList = implementsList;
}

public List<AnnotationExpr> getAnnotations() {
    return annotations;
}

public boolean isInterface() {
    return isInterface;
}

public List<TypeParameter> getTypeParameters() {
    return typeParameters;
}

public List<ClassOrInterfaceType> getExtends() {
    return extendsList;
}

public List<ClassOrInterfaceType> getImplements() {
    return implementsList;
}

@Override
public <A> void accept(VoidVisitor<A> v, A arg) {
    v.visit(this, arg);
}

@Override
public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
    return v.visit(this, arg);
}
}
节点类如下所示:

public abstract class Node {

private final int beginLine;

private final int beginColumn;

private Scope enclosingScope;

@Deprecated
public Node(int line, int column) {
    this.beginLine = line;
    this.beginColumn = column;
    this.endLine = line;
    this.endColumn = column;
}

public Node(int beginLine, int beginColumn, int endLine, int endColumn) {
    this.beginLine = beginLine;
    this.beginColumn = beginColumn;
    this.endLine = endLine;
    this.endColumn = endColumn;
}

public void setMyScope(Scope enclosingScope) {
    this.enclosingScope = enclosingScope;
}

public Scope getMyScope() {
    return enclosingScope;
}

public final int getBeginLine() {
    return beginLine;
}

public final int getBeginColumn() {
    return beginColumn;
} ... ...
现在,当我从ClassOrInterfaceDeclaration的实例调用这些方法时,除了setMyScope和getMyScope之外,任何方法都是可用的。有点新手。不知道为什么以及如何修复它

ClassOrInterfaceDeclaration的代码如下:

ClassOrInterfaceDeclaration -> TypeDeclaration -> BodyDeclaration -> Node
public final class ClassOrInterfaceDeclaration extends TypeDeclaration {

private final List<AnnotationExpr> annotations;

private final boolean isInterface;

private final List<TypeParameter> typeParameters;

private final List<ClassOrInterfaceType> extendsList;

private final List<ClassOrInterfaceType> implementsList;

public ClassOrInterfaceDeclaration(int line, int column, JavadocComment javaDoc, int modifiers, List<AnnotationExpr> annotations, boolean isInterface, String name, List<TypeParameter> typeParameters, List<ClassOrInterfaceType> extendsList, List<ClassOrInterfaceType> implementsList, List<BodyDeclaration> members) {
    super(line, column, javaDoc, name, modifiers, members);
    this.annotations = annotations;
    this.isInterface = isInterface;
    this.typeParameters = typeParameters;
    this.extendsList = extendsList;
    this.implementsList = implementsList;
}

public List<AnnotationExpr> getAnnotations() {
    return annotations;
}

public boolean isInterface() {
    return isInterface;
}

public List<TypeParameter> getTypeParameters() {
    return typeParameters;
}

public List<ClassOrInterfaceType> getExtends() {
    return extendsList;
}

public List<ClassOrInterfaceType> getImplements() {
    return implementsList;
}

@Override
public <A> void accept(VoidVisitor<A> v, A arg) {
    v.visit(this, arg);
}

@Override
public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
    return v.visit(this, arg);
}
}

TypeDeclaration和BodyDeclaration是相似的。其中没有关于行、列或范围的内容。然而,虽然beginLine和beginColumn工作得很好,但setMyScope和getMyScope却不行。后两种方法是我添加的。我怀疑我做了一些愚蠢的事情,但我无法理解。

这似乎是一个您无法引用最新类版本的问题。 可能的问题:

代码根本不会重新编译 同一src中的其他类可能存在编译错误。修复这些问题,然后重新编译。 您的类路径中可能有jar文件路径,其中jar不会被最新的jar替换。
请检查这些方框是否都打勾了。如果问题仍然存在,请让我们知道

当我声明classor interfacedeclaration n时,除了setMyScope和getMyScope之外,任何方法都是可用的;输入n,Eclipse显示了我可以使用的所有方法。Node类中除了getMyScope、setMyScope之外,还有getBeginLine等方法。它弹出了一个错误:类型ClassOrInterfaceDeclaration的方法setMyScope未定义。你能不能也放ClassOrInterfaceDeclaration代码?后两个方法是我添加的。添加这些方法后,您是否重新编译了代码?您是否已启用“自动生成”功能?类路径上是否有一个Jar文件,其中包含另一个没有这些方法的Node版本?谢谢。我重新启动了Eclipse,发现在Node类中进行的所有调整都丢失了。系统似乎因为某种原因而崩溃了。我肯定保存了这个文件。