简体   繁体   中英

public interface ITMark<E extends Comparable<E>>

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

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.

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.

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/ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM