Scala错误:类型参数不符合类类型参数边界
发布时间:2020-12-16 18:39:29 所属栏目:安全 来源:网络整理
导读:请参阅以下函数定义: class Entity[T]( val pi : T = String,val si : T = Map[Symbol,String],val tag : ClassTag[T],val address: T=AnyRef) { // some other definitions here ... def filterEntity(attribute: DiscreteAttribute[T],value: String ):Un
请参阅以下函数定义:
class Entity[T]( val pi : T => String,val si : T => Map[Symbol,String],val tag : ClassTag[T],val address: T=>AnyRef ) { // some other definitions here ... def filterEntity(attribute: DiscreteAttribute[T],value: String ):Unit={ // nothing } } 编译器给我以下错误: /Users/i-danielk/ideaProjects/saul/src/main/scala/edu/illinois/cs/cogcomp/lfs/data_model/entity/Entity.scala:67: type arguments [T] do not conform to class DiscreteAttribute's type parameter bounds [T <: AnyRef] [error] def filterEntity(attribute: DiscreteAttribute[T],value: String ):Entity[T]={ 这是DiscreteAttribute的定义: case class DiscreteAttribute[T <: AnyRef]( val name : String,val mapping: T => String,val range : Option[List[String]] )(implicit val tag : ClassTag[T]) extends TypedAttribute[T,String]{ .... } 知道我哪里错了吗? 更新:以下内容不起作用: def filterEntity(attribute: DiscreteAttribute[T <: AnyRef],value: String ):Entity[T]={ 这是错误: /Users/i-danielk/ideaProjects/saul/src/main/scala/edu/illinois/cs/cogcomp/lfs/data_model/entity/Entity.scala:67: ']' expected but '<:' found. [error] def filterEntity(attribute: DiscreteAttribute[T <: AnyRef],value: String ):Entity[T]={ Update2:以下是它的使用方法: val filteredConstituent= EdisonDataModel.constituents.filterEntity(EdisonDataModel.Eview,"Token") 哪里 object EdisonDataModel extends DataModel { val Eview = discreteAttributeOf[Constituent]('CviewName){ x=>x.getViewName } 和 def discreteAttributeOf[T <: AnyRef](name : Symbol)(f : T => String)(implicit tag : ClassTag[T]) : DiscreteAttribute[T] = { new DiscreteAttribute[T](name.toString,f,None) } 更新3: def filterEntity(attribute: DiscreteAttribute[T],value: String ):Unit={ // empty } 解决方法
您需要为影响filterEntity方法的T类型定义限制.
例如class Something [T< ;: AnyRef],以便它匹配DiscreteAttribute的限制 在您的情况下,您希望将实体声明为:class Entity [T< ;: AnyRef]. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- shell 学习第九天---分组
- angularjs – 如何在标记中使用条件绑定中的HTML
- CXF入门教程(5) -- webService异步调用模式
- OpenStack搭建企业私有云 五: Dashboard(持续更
- 尝试使用templateURL测试AngularJS指令
- Mule ESB-3.Build a webservice proxy
- scala – Akka – 重新发出“打破”消息
- bash – 用ls和grep列出带有某些扩展名的文件
- twitter-bootstrap – Bootstrap float divs从左
- osx – Bash键盘快捷键,如Alt d和Alt f [closed]
热点阅读