You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got a compiler error when trying to implement a java interface which has a method with vararg parameter using a anonymous class. It is strange 'cause it only happens when i explicit define its type. See example bellow:
// Java Interface:
public interface VarArgs {
public void method(String... s);
}
// Scala class: classScalaVarArgsextendsVarArgs {
// -- no problem on overriding it using ordinary class defmethod(s: String*) { println(s) }
}
objectScalaVarArgs {
defmain(args: Array[String]) {
//[1] Ok - no problem using inferred type valvarArgs=newVarArgs {
defmethod(s: String*) { println(s) }
}
varArgs.method("1", "2")
//[2] Ok -- no problem when explicit set its type after constructionvalb:VarArgs= varArgs
b.method("1", "2")
//[3] Ok -- no problem on calling its method
(newScalaVarArgs).method("1", "2")
(newScalaVarArgs:VarArgs).method("1", "2")
//[4] Not Ok -- error when assigning anonymous class to a explictly typed val// Compiler error: object creation impossible, since method method in trait VarArgs of type (s: <repeated...>[java.lang.String])Unit is not defined valtagged:VarArgs=newVarArgs {
defmethod(s: String*) { println(s) }
}
}
}
Alexandre Cardoso (accbel) said:
Same error when trying following case
classA {
defotherMethod(arg: VarArgs) {
//A piece of code
}
}
// Not Ok -- error when assigning anonymous class as a method parameter// Compiler error: object creation impossible, since method method in trait VarArgs of type (s: <repeated...>[java.lang.String])Unit is not definednewA().otherMethod(newVarArgs {
defmethod(s: String*) { println(s) }
}
I've got a compiler error when trying to implement a java interface which has a method with vararg parameter using a anonymous class. It is strange 'cause it only happens when i explicit define its type. See example bellow:
Note: this error/doubt was original post at scala-users mail list: http://groups.google.com/group/scala-user/browse_thread/thread/85757cea2cd25069/27817e912c89a6f5?lnk=gst&q=fabio.veronez#27817e912c89a6f5
The text was updated successfully, but these errors were encountered: