【发布时间】:2020-03-07 05:18:25
【问题描述】:
鉴于void foo(Boolean... bars) 函数,bars 的值的行为与以下函数调用中的明显不同:
- foo(),
bars = Boolean[0] - foo(null),
bars = null - foo(null, null),
bars = Boolean[2] { null, null }
为什么调用 foo(null) 会产生 bars = null 而不是 Boolean[1] { null }?
这是在 Java 8 上复制的。
【问题讨论】:
-
我希望你能得到一个编译器警告。您可以将显式数组传递给 varargs 参数,对于
foo(null),它猜测您正在尝试这样做。