Liny_@NotePad

沉迷ACG中

【注意】Win下的类名……

YOYO posted @ 2008年9月26日 05:34 in 【Java SE】 with tags windows 类名 , 1890 阅读

由于Win下的文件名不区分大小写,所以如果同一个包中有相同的类(比如下例中的TestThread类和testthread),就无法通过编译。

软院的一个同学发来一个貌似无错的程序,跑了一下才发现原来如此……

  1. class TestThread extends Thread {
  2.     private String whoami;
  3.     private long delay;
  4.     //Our constructor to store the name (whoami) and time to sleep (delay)
  5.     public TestThread(String s, long d) {
  6.         whoami = s;
  7.         delay = d;
  8.     }
  9.     //Run - the thread method similar to main() When run is finished, the thread dies.
  10.     //Run is called ** the start() method of Thread
  11.     @Override
  12.     public void run() {
  13.         //Try to sleep for the specified time
  14.         try {
  15.             sleep(delay);
  16.         } catch (InterruptedException e) {
  17.         } //Now print out our name
  18.         System.out.println("Hello World!" + whoami + "" + delay);
  19.     }
  20. }
  21. /** * Multimtest. A simple multithread thest program */
  22. public class testthread {
  23.     public static void main(String args[]) {
  24.         TestThread t1, t2, t3; //Create our test threads
  25.         t1 = new TestThread("Thread1", 1000);
  26.         t2 = new TestThread("Thread2", 2000);
  27.         t3 = new TestThread("Thread3", 3000);
  28.         //Start each of the threads
  29.         t1.start();
  30.         t2.start();
  31.         t3.start();
  32.     }
  33. }
  • 无匹配

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter