- Generic classes
(1) - Generic methods
(2)
(3)
The tricky code is <T extends Comparable>. Initially, I thought once we extends the Comparable interface, we have to @override compareTo() method. After I searched some resourses about Generic, I understood that we do not need to @override this method, when we extends the Comparable interface.The reason is that we just need to define that elements in Queue can be compared. When we call this method, We have declare which generic type we will use. In detail,all primitive types have their own Generic names,such as Integer, String,Boolean and so on.
Generic classes and methods
最新推荐文章于 2024-10-20 18:36:02 发布