java - xtend 是否支持多个构造函数?
问题描述
我正在使用 Eclipse IDE。第一个构造函数是可调用的,但不是第二个。我想知道 xtend 是否支持多个构造函数?
@Data abstract class MatchingBase implements TidilySerializable {
val List<Integer> connections
new (int componentSize) {
connections = (0 ..< componentSize).toList
}
new (List<Integer> conn) {
connections = new ArrayList<Integer>()
for (int i : 0 ..< componentSize)
connections.add(conn.get(i))
}
}
@Data class Permutation extends MatchingBase {
}
然后,如果我new Permutation(new ArrayList<Integer>())
在 Eclipse 中调用,则会将其强调为编译时错误。
解决方案
是的,它支持多个构造函数。但是,我相信由于您的第二个构造函数而发生错误。在第二个构造函数的范围内,它不知道是什么componentSize
。你的意思是像
new (List<Integer> conn) {
connections = new ArrayList<Integer>()
for (int i : 0 ..< conn.size) {
connections.add(conn.get(i))
}
}
查看此处的文档以获取有关 xtend 构造函数的更多信息
推荐阅读
- python-3.x - 如何使用层次聚类预测新观察的聚类标签?
- excel - Set Word = GetObject(, "Word.Application") 在一个子中有效,但在同一文档的其他子中无效
- android - 在 Android 应用程序上找不到带有预填充数据库表的 React-Native SQLite
- java - LocalStackContainer 集成测试 lambda
- angular - 使用 Azure DevOps 将我的 Angular Universal (SSR) 上传到 Azure 的问题
- r - R googlesheets4 将令牌作为参数传递给 read_sheet
- docker - 带有烧瓶和postgres的容器之间的通信错误
- sql - 使用 TCL 删除变量
- java - 使用 Java Stream API 收集到地图
- javascript - 删除数组中的索引 - React.js