2013-02-27 3 views
-2

switch 문을 사용하는 (내장 된) Java 메서드를 찾으려고합니다.스위치 메서드가있는 기본 Java 메서드

제 질문을 명확히하기 위해 Java switch 문을 사용하는 방법을 묻지 않습니다. 내 자신의 메서드를 만들고 switch 문을 넣을 수 있다는 것을 알았습니다.

Java에서 코드에 이러한 문이 통합 된 메서드를 찾고 있습니다.

제 질문을 더욱 명확하게하기 위해 Java API에서 switch 문을 사용하는 http://docs.oracle.com/javase/7/dofucs/api/ 메소드를 찾고 싶습니다.

감사합니다.

+4

그래서 src.zip 및 grep을 추출하십시오. –

+0

Java API에서 switch 문의 * 사용법 *을 찾고 계십니까? 도서관 자료실에서 그걸 뜯어 먹으면 도움이되지 않나요? 또한, 왜? –

답변

3

"switch"를 언급하는 소스의 모든 .java 파일 목록입니다 (대부분은 switch 문을 사용하는 것처럼 보이지만 일부는 주석으로 만 논의하는 것처럼 보입니다).

http://pastebin.com/grBqEjBE

그러나

은 원래의 질문에 대답 : 많은 예 가운데, 여기 JLabel.java에서 하나 : 실제로 자바 API에 available입니다

public String getAtIndex(int part, int index) { 
     if (index < 0 || index >= getCharCount()) { 
      return null; 
     } 
     switch (part) { 
     case AccessibleText.CHARACTER: 
      try { 
       return getText(index, 1); 
      } catch (BadLocationException e) { 
       return null; 
      } 
     case AccessibleText.WORD: 
      try { 
       String s = getText(0, getCharCount()); 
       BreakIterator words = BreakIterator.getWordInstance(getLocale()); 
       words.setText(s); 
       int end = words.following(index); 
       return s.substring(words.previous(), end); 
      } catch (BadLocationException e) { 
       return null; 
      } 
     case AccessibleText.SENTENCE: 
      try { 
       String s = getText(0, getCharCount()); 
       BreakIterator sentence = 
        BreakIterator.getSentenceInstance(getLocale()); 
       sentence.setText(s); 
       int end = sentence.following(index); 
       return s.substring(sentence.previous(), end); 
      } catch (BadLocationException e) { 
       return null; 
      } 
     default: 
      return null; 
     } 
    } 

합니다.

관련 문제