iT邦幫忙

2025 iThome 鐵人賽

DAY 20
0
  1. try-with-resources
class MyResource implements AutoCloseable {
    public void action() { System.out.print("action "); }
    public void close() { System.out.print("close "); }
}

public class Test4 {
    public static void main(String[] args) {
        try (MyResource r = new MyResource()) {
            r.action();
        }
    }
}
  1. 泛型 (Generics)
import java.util.*;

public class Test5 {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1,2,3,4);
        List<?> l2 = list;
        // l2.add(5);   // 編譯錯誤
        System.out.println(l2.get(2));
    }
}

上一篇
Google Gson
下一篇
Servlet 使用 PrintWriter
系列文
從0開始學習Java21
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言