Corey
Corey

Reputation: 1059

Call Scala generic method from Java

How can I call the following Scala method from Java?

def mult[A,B: ClassTag,C: ClassTag](rdd1:RDD[A], rdd2:RDD[B])(implicit multiplier: Multiplier[A,B,C]): RDD[C] =
    rdd1.zip(rdd2).map(p => multiplier.multiply(p._1, p._2))

Is it possible? Eclipse isn't giving me any help from its autocomplete.

Upvotes: 0

Views: 730

Answers (1)

Rex Kerr
Rex Kerr

Reputation: 167931

Ugh. Must you? The B and C ClassTags are added to the list of implicit parameters (before the explicit ones), so you can add appropriate ones generated with the scala.reflect.ClassTag object. But it's going to be ugly.

Something like (untested):

mult(rdd1, rdd2, scala.reflect.ClassTag.apply(B.class), scala.reflect.ClassTag.apply(C.class), myMult);

Upvotes: 2

Related Questions