为什么我不能使用嵌套的 IntList 来创建对象?

Why can't I use nested IntList to create an object?

为什么我不能像在 Python 中那样使用嵌套的 IntList 创建实例?

我收到错误:找不到符号 符号:方法 IntList(int,) 位置:class 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 的方法。