使用 scala 2.10.2,我有一个extends
来自类的代码,scala.swing.ListView[SomeClass]
我得到这个错误:
src/some.scala:100: error: class Some_Renderer needs to be abstract, since method componentFor in class Renderer of type (list: scala.swing.ListView[_ <: SomeClass], isSelected: Boolean, focused: Boolean, a: SomeClass, index: Int)scala.swing.Component is not defined
private class Some_Renderer extends ListView.Renderer[SomeClass]
编辑:“一个额外的注意”实际上是这里的错误,因为评论B[String]
必须是B[_]
.
编辑:一些真实的例子如下
我已将其复制为以下示例,但有一个额外的注释:
scala> class B[A] { val m : Int = 0 }
defined class B
scala> abstract class C[A] { def f(l: B[_]):Int }
defined class C
scala> private class D extends C[String] { def f(l: B[String]):Int = { l.m } }
<console>:9: error: class D needs to be abstract, since method f in class C of type (l: B[_])Int is not defined
(Note that B[_] does not match B[String]: their type parameters differ)
private class D extends C[String] { def f(l: B[String]):Int = { l.m } }
编辑:MWE
import scala.swing.{Component, Label, ListView}
class Test
object Retn extends Label { opaque = false }
private class TestRenderer extends ListView.Renderer[Test]
{
def componentFor(list: ListView[_], isSelected: Boolean, focused: Boolean, test: Test, index: Int): Component =
{
val retn = Retn
retn
}
}
<console>:9: error: class TestRenderer needs to be abstract, since method componentFor in class Renderer of type (list: scala.swing.ListView[_ <: Test], isSelected: Boolean, focused: Boolean, a: Test, index: Int)scala.swing.Component is not defined
private class TestRenderer extends ListView.Renderer[Test]
^
编辑:MWE
我只是想修补那行代码,绝不scala
做编程。但是我不明白这个例子有什么问题。我发现了类似的问题,但没有用这个下划线(“ ”)的东西。_
该示例尝试为f
class中的抽象方法提供实现C[A]
。
感谢您对此问题的评论或回答。