Reputation: 111
I'm trying to invoke a constructor that takes a varargs in Scala. The constructor is written in a Java class and takes two parameters, a Block
and IBlockState...
. The following code doesn't seem to compile, however:
new BlockStateList(this, Seq[IBlockState[_ <: Comparable[_]]](FACING, DAMAGE):_*)
The compiler reports with this message:
Error:(58, 66) type mismatch;
found : Seq[net.minecraft.server.v1_8_R3.IBlockState[_ <: Comparable[_]]]
required: Seq[net.minecraft.server.v1_8_R3.IBlockState[? <: Comparable[?0]] forSome { type ?0 <: Comparable[?0] }]
new BlockStateList(this, Seq[IBlockState[_ <: Comparable[_]]](FACING, DAMAGE):_*)
^
The required type doesn't seem syntactically correct to me, and I have no idea as to what it wants me to provide.
All help is greatly appreciated!
Upvotes: 0
Views: 159
Reputation: 5977
The problem is not related to varargs, but to the content of the sequence.
As I have deduced Comparable is restricted to its type parameter. Something like
trait Comparable[C <: Comparable[C]]
See more info about this pattern. So to denote this type requirement you need advanced existential types specification. MyType[_]
is shortcut to full MyType[A] forSome {type A}
. In your case compiler expects
Seq[IBlockState[_ <: Comparable[C]] forSome { type C <: Comparable[C] }]()
instead of
Seq[IBlockState[_ <: Comparable[_]]]()
Upvotes: 2