java - 为什么我不能使用嵌套的 IntList 创建对象?
问题描述
为什么我不能像在 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
.
推荐阅读
- python - 在 python 的计算机逻辑中,分布规律是否有效?
- flutter - 是否有理由不升级 Flutter SDK 最小约束?
- swift - 在 NSBatchDeleteRequest 之后使用动画更新 tableview
- python-3.x - np.mean() 给出错误的平均值?
- bash - 来自 7 GB 文本文件或许多较小文件的 grep
- java - Selenium 服务器并行测试错误:无效的会话 ID
- mysql - 如何按mysql中的计算列排序
- javascript - 来自 getElementById 的随机图像不适用于多个过滤器
- ios - Xcode iPhone模拟器键盘按弄乱计算机音频质量
- java - Spring Boot 多个参数 - GET 请求