[英]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 我正在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.
仅供参考,最常见的Java类型(例如Integer,String,Date等)都是可比较的。
ITMark
is a raw type because it has no declared generic parameters. ITMark
是原始类型,因为它没有声明的通用参数。
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. 如果您声明
TMark
为TMark<E extends Comparable<E>> implements ITMark<E>
,则它将不再是原始类型,因为您声明了其通用参数。
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/ . 有关泛型的良好介绍,请阅读Java教程, http: //java.sun.com/docs/books/effective/generics.pdf上约书亚·布洛赫(Joshua Bloch)的有效Java的免费章节以及https://上的许多关于泛型的文章。 /www.ibm.com/developerworks/java/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.