2

now i want to implement this interface with the class. so how should i do it?

public class TMark<E> implements ITMark{}

is this the way but throwing errors

I am getting the following:

ITMark is a raw type. References to generate type ITMark<E> should be parametrized

I am implementing this code in Eclipse IDE

adarshr
  • 61,315
  • 23
  • 138
  • 167
karan
  • 21
  • 2

3 Answers3

0

Do this:

public class TMark<SomeComparableClass> implements ITMark<SomeComparableClass> {
    // implement the methods of ITMark for type SomeComparableClass
}

You must specify which Comparable class you are implementing for this class. FYI, most common java types (eg Integer, String, Date, etc) are Comparable.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

ITMark is a raw type because it has no declared generic parameters.

If you declared TMark as TMark<E extends Comparable<E>> implements ITMark<E>, it would not longer be a raw type because you declared its generic parameter.

Jeffrey
  • 44,417
  • 8
  • 90
  • 141
0

You left out the generic parameter, that is, the part that goes in the angle brackets. You need something like:

public class TMark <E extends Comparable <E> implements ITMark<E>
{
    ...
}

For a particular generic type you put a suitable 'Comparable' type inside the angle brackets, something like:

public class IntegerTMark extends TMark <Integer>
{
    ...
}

For a good introduction to generics, read the Java tutorials, the free chapter from Joshua Bloch's Effective Java at http://java.sun.com/docs/books/effective/generics.pdf and the many articles about generics at https://www.ibm.com/developerworks/java/.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Lew Bloch
  • 3,364
  • 1
  • 16
  • 10