简体   繁体   English

抑制 Scala 中的“参数化重载隐式方法作为视图边界不可见”警告

[英]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.

相关问题 什么“参数化重载隐式方法不可见为视图边界”编译器警告意味着什么? - What does “parameterized overloaded implicit methods are not visible as view bounds” compiler warning mean? 定义 Scala 特征的隐式视图边界 - Defining implicit view-bounds on Scala traits Scala隐式函数参数化 - Scala implicit function parameterized 引用scala中的重载方法 - reference to overloaded methods in scala 如何在Scala中关闭特定的Implicit,以防止由于重载方法而导致代码编译? - How to turn off specific Implicit's in Scala that prevent code from compiling due to overloaded methods? 在Scala中,有没有办法让两个重载方法只在隐含是否可用的情况下有所不同? - In Scala, is there a way to have two overloaded methods that only differ in whether an implicit is available? 是否可以使用Mockito和Specs2模拟带有视图边界的Scala方法? - Is it possible to mock Scala methods with view bounds with Mockito and Specs2? Scala参数化方法和算术运算 - Scala parameterized methods and arithmetic operations 在Scala中使用参数化类型进行类层次结构的隐式转换? - Implicit conversion for class hierarchy with parameterized types in Scala? 对重载方法的Scala通用调用 - Scala generic invocation on overloaded methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM