【发布时间】:2017-12-01 20:40:09
【问题描述】:
我仍在学习,目前正在尝试使用嵌套的 STATIC 类实现 DoublyLinkedLists,并收到以下错误:
No enclosing instance of the type OuterClass.StaticNestedClass is accessible in scope
实际错误:No enclosing instance of the type SolutionDLL.Node is accessible in scope
我在外部类 SolutionDLL 类中有两个 STATIC 嵌套类:
class SolutionDLL {
public static class Node {
private Object element;
private Node next;
private Node previous;
Node(Object elementIn, Node nextNodeIn, Node prevNodeIn) {
element = elementIn;
next = nextNodeIn;
previous = prevNodeIn;
}
public Object getElement() {
return element;
}
public Node getNext() {
return next;
}
public Node getPrevious() {
return previous;
}
}
public static class DLList {
public void addFirst(Node n) {
SolutionDLL.Node tempNode = new SolutionDLL.Node(
SolutionDLL.Node.this.getElement(),
SolutionDLL.Node.this.getNext(),
SolutionDLL.Node.this.getPrevious());
// do something
}
}
}
不管我这样打电话:SolutionDLL.Node.this.getElement()
像这样:Node.this.getElement()
我仍然得到错误。我已经给出了框架代码,这是我第一次使用嵌套类实现。因此,我们将不胜感激任何帮助。 谢谢!
【问题讨论】:
-
您使用的语法仅适用于内部类。这里没有内部类。
标签: java class inner-classes