简体   繁体   中英

Suppressing “parameterized overloaded implicit methods are not visible as view bounds” warning in Scala

Is it possible to suppress this specific warning by using @SuppressWarnings(???) ? (I don't intend to use this conversion as a view bound, so the warning isn't useful.)

Unfortunately not. The compiler ignores @SuppressWarnings . Also see this question .

While you cannot suppress this warning through @SuppressWarnings , you can simply rename one of the overloads that the compiler is warning about. If you don't want to rename it because it is also explictly called, make the method non-implicit and add another (differently named) implicit conversion that forwards to the former.

In other words, you should by example turn this:

class MyClass
object MyClass {
   implicit def myConv: MyClass = error("TODO")
   implicit def myConv[X](value: X): MyClass = error("TODO")
}

into this:

class MyClass
object MyClass {
   implicit def myConv: MyClass = error("TODO")
   def myConv[X](value: X): MyClass = error("TODO") // made it non implicit
   implicit def myConv2[X](value: X): MyClass = myConv( value ) // renamed so that it is not an overload anymore
}

Note that the warning is only emitted in scala 2.9.x, it is by default not emitted anymore in scala 2.10 (but the actual problem that the warning is talking about is still there - the warning message was only removed because it was deemed too noisy with the new surge in type class usage).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM