简体   繁体   English

Scala的Java可变长度参数

[英]Java Variable Length Arguments to Scala

I am implementing an extension of an abstract class from that library which has this signature: 我正在实现具有该签名的该库的抽象类的扩展:

Object filter(Object var, JinjavaInterpreter interpreter, String... args);

Which I think I should implement as the following in Scala 我认为我应该在Scala中实现以下内容

def filter(obj: Any, jinjavaInterpreter: JinjavaInterpreter, args: String*): Any = {
...
}

However, when I try to access items from args (eg args(0) , I get type coercion errors: Cannot coerce '0' of class java.lang.String to class [Ljava.lang.String; 但是,当我尝试从args访问项目(例如args(0) ,出现类型强制错误): Cannot coerce '0' of class java.lang.String to class [Ljava.lang.String;

It seems the coercion errors means that class String can't be cast to String[]: 强制错误似乎意味着不能将String类转换为String []:

Cannot coerce '0' of class java.lang.String to class [Ljava.lang.String; 无法将类java.lang.String的'0'强制为类[Ljava.lang.String;

I bet args(0) is of class String which is correct. 我敢打赌args(0)是String类,这是正确的。

Your signature is correct and I also bet that the error is other else. 您的签名是正确的,我也敢打赌错误是其他错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM