1

I have a class ExtA which contains a filter function to filter an ArrayList:

public ExtA<T> filt(...)
{

 //code


}

when I compile it is giving me error: cannot find symbol- class T. Why is this?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user3126119
  • 323
  • 1
  • 3
  • 10

2 Answers2

5

You have to tell it, that T is a generic type in this case:

public <T> ExtA<T> filt(Func<T, Boolean> a)

You declared your interface with the symbol T, but that symbol is only valid in the interface declaration itself. The T you are using in your method is a different T. You have to declare it again, since the method is not implemented inside the interface declaration.

Sibbo
  • 3,796
  • 2
  • 23
  • 41
  • I don't know how your ExtA is declared. You should maybe edit the question, or create a new one... – Sibbo Jan 03 '14 at 17:02
  • Well, you have to declare it as ExtA. The tells the compiler, that it takes one type argument. – Sibbo Jan 03 '14 at 17:06
  • I guess you should also add the same type argument to ArrayList. But I don't really know. – Sibbo Jan 03 '14 at 17:10
3

You have to put the parameter on the method:

public <T> ExtA<T> filt(Func<T, Boolean> a) {
// method code
}
Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49