如何从Java调用具有数值参数的Scala方法
我有一个Scala方法,它接受Numeric[T]
对象:
def needNumeric[T](value: T)(implicit n: Numeric[T]) = {
// do something
}
如何从Java中调用这个方法?我想出的最好办法是:
needNumeric(0, scala.math.Numeric.IntIsIntegral$.MODULE$);
但代码看起来很难看,也不是很通用。有更好的方法吗
你可以在下面搜索框中键入要查询的问题!
我有一个Scala方法,它接受Numeric[T]
对象:
def needNumeric[T](value: T)(implicit n: Numeric[T]) = {
// do something
}
如何从Java中调用这个方法?我想出的最好办法是:
needNumeric(0, scala.math.Numeric.IntIsIntegral$.MODULE$);
但代码看起来很难看,也不是很通用。有更好的方法吗
# 1 楼答案
解决这个丑陋问题的一个小办法是:定义Java便捷访问,比如
折衷是,它允许调用任何需要
Numeric
的方法,而无需修改它