2010-12-31 2 views
3

는 최근에 나는 종종 다음과 같은 자바 코드를 읽을 수 있습니다Java IDE에서 소스 코드의 유형 정의를 축소 할 수 있습니까?

LinkedHashMap<String, Integer> totals = new LinkedHashMap<String, Integer>(listOfRows.get(0)) 
for (LinkedHashMap<String, Integer> row : (ArrayList<LinkedHashMap<String,Integer>>) table.getValue()) {  
    for(Entry<String, Integer> elem : row.entrySet()) { 
     String colName=elem.getKey(); 
     int Value=elem.getValue(); 
     int oldValue=totals.get(colName); 

     int sum = Value + oldValue; 
     totals.put(colName, sum); 
    } 
} 

인해 길고 중첩 된 유형 정의에 간단한 알고리즘은 매우 가려진된다. 그래서 나는 제거하거나 같은 종류없이 자바 코드를 볼 수 내 IDE와 유형 정의를 축소 할 수달라고 : 유형 정의를 축소하는 것입니다 물론

totals = new (listOfRows.get(0)) 
for (row : table.getValue()) {  
    for(elem : row.entrySet()) { 
     colName=elem.getKey(); 
     Value=elem.getValue(); 
     oldValue=totals.get(colName); 

     sum = Value + oldValue; 
     totals.put(colName, sum); 
    } 
} 

가장 좋은 방법,하지만 위에 마우스를 이동할 때 variable은 유형을 툴팁으로 표시합니다. 이 작업을 수행 할 수있는 IDE 용 Java IDE 또는 플러그인이 있습니까?

+0

.NET (비주얼 스튜디오)이 기능을, 그들은 그것을 호출 "지역"을 가지고있다. 몇 달 전 이클립스에서이 기능을 찾으려고했으나 아무 것도 발견하지 못했습니다. :( –

답변

5

IntelliJ IDEA은 선언 오른쪽에있는 유형을 <~>으로 변환합니다. 그래서 :

Map<Integer, String> m = new HashMap<~>(); 

이것은 편집기/코드 폴딩/일반 생성자 및 방법 매개 변수 속성을 통해 설정 가능하고 community edition of the IDE 무료 :

Map<Integer, String> m = new HashMap<Integer, String>(); 

는 다음과 같이 접힌 나타납니다.


아니면 에게 추론 유형이 스칼라, 사용할 수 있습니다

val totals = new mutable.Map[String, Int] 
for { 
    row <- table.getValue 
    (colName, value) <- row.entrySet 
} totals += (colName -> (value + totals.get(colName) getOrElse 0) 
관련 문제