博客统计信息

用户名:love-xiaoli
文章数:2
评论数:0
访问量:574
无忧币:20
博客积分:20
博客等级:1
注册日期:2009-06-05



今天写了一个小程序,
public class ThreadTest extends Thread {
    public static void main(String[] args) throws InterruptedException {
        ThreadTest tt = new ThreadTest();
        tt.start();
        tt.interrupt();
        System.out.println(tt.isInterrupted());
    }
    public void run() {
        int i=0;
        while (i<9) {
            System.out.println("thread is running!");
            i ;
        }
    }
}
哈哈,满怀信心的想执行完这个程序线程就会被中断了,可是现实总是很残忍,程序运行到底,thread is running打印了9次,靠,怪了,为什么会这样?为了彻底..
类别:未分类|阅读(149)|回复(0)|(0)阅读全文>>
2009-06-05 22:30:53
public class Test {
public static void main(String[] args) {
Integer i1 = 127;
Integer i2 = 127;
Integer i3 = Integer.valueOf(127);
if (i1 == i2)
System.out.println("i1 == i2 is true!");
else
System.out.println("i1 == i2 is false!");
if (i1 >= i2)
System.out.println("i1 >= i2 is true!");
else
System.out.println("i1 >= i2 is false!");
if (i1 == i3)
System.out.println("i1 == i3 is true!");
else
System.out.println("i1 == i3 is false!");
}
}
当值是127时,输出是:
i1 == i2 is true!
i1 >= i2 is true!
i1 == i3 is true!
当值是128时,输出是:
i1 == i2 is false!
i1 >= i2 is true!
i1 == i3 is false!
说明:
我使用的是Sun JDK 1.5.0_03-b07 和 Eclipse 3.2M4。
“Integer i1 = 127;”在JDK1.4下不能编译通过的,会提示:“ Type mismatch: cannot convert from int to Integer”的错误,一般改写为:“Integer i1 = new Integer(127);”。
“Integer i1 = 127;”在JDK1.5下可以编译通过的,这就是自动装箱(Autoboxing)和自动拆箱(Auto-Unboxing)。自动装箱(Autoboxing)特性让J..
类别:未分类|阅读(153)|回复(0)|(0)阅读全文>>

我的技术圈(0)

更多>>

背景音乐

我的音乐

00:00 | 00:00

最新评论