1
5
在Java中,对的调用
获得与varargs类似功能的一种方法是简单地编写多个构造函数,这些构造函数向上传递默认值。
不过,如果参数的数量很高,这可能会变得很麻烦,但该示例仅使用3
以下是对它们的称呼:
|
2
3
你不能。正如错误所说,
理论上你可以做到,但它是否干净——这有待商榷:
没有通用的解决方案——你可以找到一种方法将整个事情简化为一个
|
3
3
遵守错误消息,将代码压缩为一行:
通常的方法是工厂方法,适用于任意复杂的代码:
|
4
2
你可以写
然后将此方法和所有args构造函数一起使用,如下所示:
这是有争议的,如果这是否更干净,我想说这取决于当前项目中采用的风格。 |