2015-09-17 9 views
5

देखें निम्नलिखित समारोह परिभाषा:स्काला त्रुटि: प्रकार तर्क वर्ग प्रकार पैरामीटर सीमा के अनुरूप नहीं है

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]{ 
.... 
} 

कोई विचार जहां मैं गलत हो रहा हूं?

अद्यतन: निम्नलिखित काम नहीं करता है या तो:

/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") 

जहां

def filterEntity(attribute: DiscreteAttribute[T <: AnyRef], value: String):Entity[T]={ 

यहाँ त्रुटि है

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 
    } 
+2

'filterEntity' में' टी' कहां से आता है? –

+0

आपका कोड नमूना अधूरा है। FilterEntity – Daenyth

उत्तर

4

आप टी प्रकार है कि filterEntity विधि प्रभावित कर रहा है के लिए कोई प्रतिबंध को परिभाषित करने की जरूरत है।

उदा। class Something[T <: AnyRef] ताकि यह DiscreteAttribute

पर प्रतिबंध से मेल खाता है, तो आप अपने मामले में Entity की घोषणा करना चाहते हैं: class Entity[T <: AnyRef]

+0

के परिभाषित वातावरण को पोस्ट करें यह देखें कि यह काम नहीं करता है: 'def filterEntity (विशेषता: DiscreteAttribute [टी <: AnyRef], मान: स्ट्रिंग): इकाई [टी] = {' – Daniel

+0

आपको इसे उपयोग में नहीं बदला जाना चाहिए लेकिन परिभाषा। इस सवाल पर टिप्पणियां देखें कि आपका उदाहरण अपूर्ण है। – emilianogc

+0

मैंने फ़ंक्शन की परिभाषा (पहला कोड) पूरा किया। कोई उपाय? – Daniel

संबंधित मुद्दे