He,
How to call from Java a Scala case class which has an implicit paramter?
Scala:
object Loggable {
case class RunUnit(val id : Integer) {
override def toString() = id.toString()
}
case class Run(
val id : Integer, val unit : RunUnit, val start : Long
)(implicit db : DB) { ... }
}
Java:
public class JTest {
public static void main(String[] args) {
// works fine
Loggable.RunUnit ru = new Loggable.RunUnit(4711);
// how to add the implicit parameter???
new Loggable.Run(new Integer(4711), ru, 0L);
}
}
Thanks,
/nm
You would have to provide the implicit explicitly. Try this:
new Loggable.Run(new Integer(4711), ru, 0L, db);
I tried to use javap to see what the signature are, and on a top level case class, there is simply an extra parameter to the constructor.
Edit: using your code (with a dummy DB class):
scala> :javap Loggable$Run
[snip]
public Loggable$Run(java.lang.Integer, Loggable$RunUnit, long, DB);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With