私はこのようなNumber Wrapperを持っています
class NumWrapper[A<:AnyVal](var v: A)(implicit n:Numeric[A]) {
def +(other: A): NumWrapper[A] = {
new NumWrapper(n.plus(v, other))
}
def -(other: A): NumWrapper[A] = {
new NumWrapper(n.minus(v, other))
}
}
すべて正常に動作します。しかし、暗黙的な変換が必要な場合は、次のようにコンパニオン クラスを作成します。
object NumWrapper {
implicit def toNumWrapper[A<:AnyVal](v: A) = new NumWrapper[A](v)
}
しかし、コンパイル時にエラーが発生しました:
パラメータ n の暗黙的な値が見つかりませんでした: Numeric[A]
ここで何が問題なのですか? コンパイル時にタイプ A の暗黙的な一致を見つけようとしているのはなぜですか?
ご助力ありがとうございます。