7

See the following function definition:

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 
      }

}

The compiler gives me the following error:

/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]={

And here is the definition of the 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]{
....
}

Any idea where I am going wrong?

Update: The following does not work either:

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

Here is the error:

 /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: here is how it's been used:

   val filteredConstituent= EdisonDataModel.constituents.filterEntity(EdisonDataModel.Eview,"Token")

where

object EdisonDataModel extends DataModel {
  val Eview = discreteAttributeOf[Constituent]('CviewName){
    x=>x.getViewName
}

and

  def discreteAttributeOf[T <: AnyRef](name : Symbol)(f : T => String)(implicit tag : ClassTag[T]) : DiscreteAttribute[T] = {
   new DiscreteAttribute[T](name.toString,f,None)
  }

Update 3: The same error holds for the following function definition:

  def filterEntity(attribute: DiscreteAttribute[T], value: String ):Unit={
      // empty 
  }
2
  • 2
    Where does the T in filterEntity come from? Commented Sep 17, 2015 at 17:40
  • Your code sample here is incomplete. Post the defining environment of filterEntity Commented Sep 17, 2015 at 18:16

1 Answer 1

6

You need to define a restriction for the T type that is affecting the filterEntity method.

e.g. class Something[T <: AnyRef] so that it matches the restriction on DiscreteAttribute

In your case you want to have the declaration of Entity as: class Entity[T <: AnyRef].

Sign up to request clarification or add additional context in comments.

4 Comments

See this does not work either: def filterEntity(attribute: DiscreteAttribute[T <: AnyRef], value: String ):Entity[T]={
You need to change it not in the usage but the definition. See comments on the question saying that your example is incomplete.
I completed the definition of the function (the first code). Any idea?
But where is the type T coming from? I'm guessing the class that contains the filterEntity method is defined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.