IntelliJ IDEA Live Templates
善用Live Templates寫code速度++
IntelliJ IDEA Live Templates
盤點IDEA中Tab的實用招式,再配上alt+insert就能橫著走了
基本聲明
psvm或main ▶ main 方法
st ▶ String
prsf ▶ private static final
psf ▶ public static final
psfi ▶ public static final int
psfs ▶ public static final String
創立物件
類名.new ▶ new 類名()
new 類名().var或.val ▶ 類 物件名 = new 類();
new 類名().field ▶ 在方法外聲明一個成員變量,並在這裡初始化一個
sout ▶ System.out.println();
souf ▶ System.out.printf("");
"say something".sout ▶ System.out.println("say something");
obj.sout ▶ System.out.println(obj);
obj.soutv ▶ System.out.println("obj = " + obj);
// 標準錯誤輸出流,這個無緩衝,顯示的位置可能跟你想像的不同
obj.serr ▶ System.err.println(obj);
遍歷相關
fori ▶ for (int i = 0; i < ; i++)
itar ▶ for (int i = 0; i < arr.length; i++)
iter ▶ foreach
數組或集合物件.for ▶ foreach
數組物件.forr ▶ for (int i = arr.length - 1; i >= 0; i--) // 反向
itit ▶ 遍歷,while (iterator.hasNext()) { iterator.next()
類型轉換
// 適用於多態物件,例如Object obj = new String();
instr ▶ 檢查包含 instanceof 的物件類型並向下轉換
obj.cast ▶ ((String) obj)
((String) obj).var ▶ String obj1 = (String) obj;
也可以一次搞定
obj.castvar ▶ String s = (String) obj;
if相關
bool.if ▶ if (bool) {
obj.null ▶ if (obj == null) {
obj.nn ▶ if (obj != null) {
異常相關
執行語句();.try ▶ 用try-catch包裹
thr ▶ throw new
new RuntimeException().throw ▶ throw new RuntimeException();
其他
"some string".format ▶ 格式化字串
物件.synchronized ▶ synchronized (obj) {
obj.return ▶ return obj;
在方法上/** + Enter ▶ 產生方法與參數說明
上次修改於 2021-12-03