şu işlevi tanımı bakınız:Scala hatası: tip argümanlar sınıf türü parametre sınırları uymayan
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
}
}
derleyici bana aşağıdaki hatayı veriyor:
/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]={
Ve burada tanımıdır 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]{
....
}
yanlış gidiyorum fikrin var mı?
Güncelleme: Aşağıdaki çalışmıyor ya:
/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: burada kullanıldıktan hesaplanır:
val filteredConstituent= EdisonDataModel.constituents.filterEntity(EdisonDataModel.Eview,"Token")
İşte
def filterEntity(attribute: DiscreteAttribute[T <: AnyRef], value: String):Entity[T]={
hatadır
object EdisonDataModel extends DataModel {
val Eview = discreteAttributeOf[Constituent]('CviewName){
x=>x.getViewName
}
ve
def discreteAttributeOf[T <: AnyRef](name : Symbol)(f : T => String)(implicit tag : ClassTag[T]) : DiscreteAttribute[T] = {
new DiscreteAttribute[T](name.toString,f,None)
}
Güncelleme 3: aynı hata İzleyen fonksiyon, tanımı için geçerlidir: Bu filterEntity yöntemi etkileyen T tipi için bir kısıtlama tanımlamak gerekir
def filterEntity(attribute: DiscreteAttribute[T], value: String):Unit={
// empty
}
'filterEntity' içinde' T' nereden geliyor? –
Kod örneğiniz eksik. FilterEntity – Daenyth