[英]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(???)
?是否可以通过使用@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
.编译器忽略@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.虽然您无法通过@SuppressWarnings
抑制此警告,但您可以简单地重命名编译器警告的重载之一。 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).请注意,警告仅在 scala 2.9.x 中发出,默认情况下在 scala 2.10 中不再发出(但警告所讨论的实际问题仍然存在 - 警告消息仅被删除,因为它被认为太嘈杂使用 class 类型的新激增)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.