开发者

How to compare 2 objects of generic type

开发者 https://www.devze.com 2023-01-21 19:52 出处:网络
Is there a way to compare two objects that are generic? I\'m supposed to find the largest object in a linked list. My开发者_如何学编程 first guess was to use the Object\'s class compareTo method, but

Is there a way to compare two objects that are generic? I'm supposed to find the largest object in a linked list. My开发者_如何学编程 first guess was to use the Object's class compareTo method, but I couldn't get that to work. Thanks


I assume that the language is Java. (since you mentioned Object and compareTo)

I suggest you to have a have a look into Comparator and Comparable interfaces.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号