- 4
- 0
- 约1.59万字
- 约 10页
- 2018-02-06 发布于浙江
- 举报
3. Comparable可比较接口 public interface ComparableT { int compareTo(T o) //比较对象 } 其中,T是Comparable接口的参数,表示一个类。 * MyDate类对象比较大小 public class MyDate implements ComparableMyDate { public int compareTo(MyDate d) //约定比较日期大小的规则,返回-1、0、1 { if (this.year==d.year this.month==d.month this.day==d.day) return 0; return (this.yeard.year || this.year==d.year this.monthd.month || this.year==d.year this.month==d.month this.dayd.day) ? 1 : -1; } } * Comparable 接口举例 public class MyDate implements ComparableMyDate //类声明 {…. public stati
原创力文档

文档评论(0)