为什么我不能像在 Python 中那样使用嵌套的 IntList 创建实例?
我收到错误:找不到符号符号:方法 IntList(int,) 位置:类 IntList
class Link:
empty = ()
def __init__(self, first, rest=empty):
assert rest is Link.empty or isinstance(rest, Link)
self.first = first
self.rest = rest
s = Link(3, Link(4, Link(5)))
public class IntList {
public int first;
public IntList rest;
public IntList(int f, IntList r) {
first = f;
rest = r;
}
public static void main(String[] args) {
IntList L = new IntList(15, IntList(10, null));
}
}
您需要添加new
到您的第二个IntList
实例:
IntList L = new IntList(15, new IntList(10, null));
^^^
没有这个,它会试图找到一个名为IntList
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句