I have java function like this

public static CollectionReader createCollectionReader(
        Class<? extends CollectionReader> readerClass, TypeSystemDescription typeSystem,
        Object... configurationData) 

I'd like to make a partially apply function from this and specify some argument for Object... part. I am not sure if this is possible. I tried

val partiallyApply = createCollectionReader(_:Class[_ <: CollectionReader], _:TypeSystemDescription,
                                           "IncludeGoldStandardAnnotations", new Boolean("true"), 
                                           "EndIndex", new Integer("-1"), _:_*) // Doesn't work

and want it to be use as

val reader = partiallyApply(classOf[someReader], someType:TypeSystemDescription, 
"other", "configurationData", "beside", "those_four_that_already_applied_too"]

but this doesn't seems to work. Also, is this Object... has a technical name ?

EDIT: change code a little bit (my mistake .. I forgot to put val name in it) and add example of usage I want to.

EDIT2:I think my main question is that it is possible to do a partially apply function on vararg ?

EDIT3: Thanks to elbowich's suggestion. I come up with

def createCollectionReaderReadAll(cls: Class[_ <: CollectionReader], ts: TypeSystemDescription, cfg: AnyRef*) =
  createCollectionReader(cls, ts,
    Seq("IncludeGoldStandardAnnotations", new Boolean("true"), "EndIndex", new Integer("-1")) ++ cfg: _*)

work perfectly fine

有帮助吗?

解决方案

I don't think you can partially apply varargs, I'd do it like this:

def method1(x: Int, cfg: String*) = cfg
def method2(x: Int, cfg: String*) = method1(x, Seq("preset", "cfg") ++ cfg:_*)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top