程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> J2SE >> J2SE 1.5 Tiger新特性學習(4)

J2SE 1.5 Tiger新特性學習(4)

編輯:J2SE

結果:

C:\tiger>javac -d c:\tiger\cls c:\tiger\src\SimpleEnum.Java

C:\tiger>Java -classpath c:\tiger\cls tigers.SimpleEnum

A

ABCD

D

{A=something0 , B=something0 1 , C=something0 1 2 , D=something0 1 2 3 }

A = something0

B = something0 1

C = something0 1 2

D = something0 1 2 3

六、在類定義上使用泛型和繼承

package tigers;

import Java.io.UnsupportedEncodingException;

public class GenericExtends {
   public static void main(String[] args) {
     try {
       ActionToucher.execute(
         new Action<NoSuchMethodException>() {
           public void method() throws NoSuchMethodException {
             System.out.println("Action<NoSuchMethodException>");
           }
         }
       );
       ActionToucher.execute(
         new Action<NoSuchFIEldException>() {
           public void method() throws NoSuchFIEldException {
             System.out.println("Action<NoSuchFIEldException>");
           }
         }
       );
       ActionToucher.execute(
         new Action<UnsupportedEncodingException>() {
           public void method() throws UnsupportedEncodingException {
             System.out.println("Action<UnsupportedEncodingException>");
           }
         }
       );
     } catch (NoSuchMethodException e) {
       e.printStackTrace();
     } catch (NoSuchFIEldException e) {
       e.printStackTrace();
     } catch (UnsupportedEncodingException e) {
       e.printStackTrace();
     }
   }
}
interface Action<E extends Exception> {
   void method() throws E;
}
class ActionToucher {
   public static <E extends Exception> void execute(Action<E> action) throws E {
     action.method();
   }
}

C:\tiger>javac -d c:\tiger\cls\ c:\tiger\src\*.Java

Note: c:\tiger\src\GenericIdentify.Java uses unchecked or unsafe Operations.

Note: Recompile with -Xlint:unchecked for details.

C:\tiger>Java -classpath c:\tiger\cls tigers.GenericExtends

Action

Action

Action

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved