【发布时间】:2012-08-26 13:34:20
【问题描述】:
我有一个List<Thing>,我想将它传递给声明为doIt(final Thing... things) 的方法。有没有办法做到这一点?
代码看起来像这样:
public doIt(final Thing... things)
{
// things get done here
}
List<Thing> things = /* initialized with all my things */;
doIt(things);
该代码显然不起作用,因为 doIt() 采用 Thing 而不是 List<Thing>。
有没有办法将列表作为可变参数传递?
这是在 Android 应用程序中,但我不明白为什么该解决方案不适用于任何 Java
【问题讨论】:
标签: java android list variadic-functions