Chinaunix首页 | 论坛 | 博客
  • 博客访问: 179536
  • 博文数量: 6
  • 博客积分: 1425
  • 博客等级: 上尉
  • 技术积分: 575
  • 用 户 组: 普通用户
  • 注册时间: 2005-09-21 15:56
文章分类

全部博文(6)

文章存档

2008年(6)

我的朋友

分类: Java

2008-09-18 14:46:14

public static Comparator integerComparator() {
        return new Comparator() {
           
            public int compare(Object o1, Object o2) {
                int val1 = ((Integer)o1).intValue();
                int val2 = ((Integer)o2).intValue();
                return (val1
            }
        };
    }

这个叫Anonymous Inner Classes,为了简化程序写法。
在看一个例子
class CloseFrame extends Frame{
     Label label;
     CloseFrame(String title) {
     super(title);
     label = new Label("Close the frame.");
     this.addWindowListener(new WindowAdapter(){
         public void windowClosing(WindowEvent e){
             dispose();
             System.exit(1);
         }
     });
}

可以写为:
class CloseFrame extends Frame{
     Label label;
     CloseFrame(String title) {
     super(title);
     label = new Label("Close the frame.");
     this.addWindowListener(new CFListener());
     class CFListener extends WindowAdapter {
     {
         public void windowClosing(WindowEvent e){
             dispose();
             System.exit(1);
         }
     }
}


阅读(1704) | 评论(0) | 转发(0) |
0

上一篇:use case

下一篇:java的synchronized方法和快

给主人留下些什么吧!~~