2015-02-17 147 views
9

有沒有什麼辦法可以用快捷方式在try-catch塊外面拉變量?例如:提升Intellij IDEA?

來自:

try{ 
    AbstractList<Type> t1 = new ArrayList<Type>(); 
} catch (Exception e) { 
    ... 
} 

AbstractList<Type> t1; 
try{ 
    t1 = new ArrayList<Type>(); 
} catch (Exception e) { 
    ... 
} 

回答

11

我知道如何與一些快捷方式做到這一點:

  1. 把你的光標放在t1,然後「顯示意圖行動「。從那裏選擇「拆分爲聲明和分配」。您的代碼現在看起來像這樣:

    try { 
        AbstractList<String> t1; 
        t1 = new ArrayList<String>(); 
    } catch (Exception e) { 
        e.printStackTrace(); 
    } 
    
  2. 將光標置於聲明行。
  3. 做「向上移動聲明」操作。現在,你的代碼看起來就像這樣:

    AbstractList<String> t1; 
    try { 
        t1 = new ArrayList<String>(); 
    } catch (Exception e) { 
        e.printStackTrace(); 
    } 
    
+0

謝謝。順便提一下,上移動作是ctrl-shift-up。 – vikingsteve 2015-02-18 08:09:33

+0

@vikingsteve是啊我感覺不好我沒有給鍵盤快捷鍵,但我在Mac上,並習慣了PC,所以我改變了很多我的設置。我的快捷鍵與除我以外的任何人無關。 – 2015-02-18 18:08:11