带有开关方法的默认java方法

带有开关方法的默认java方法,java,switch-statement,Java,Switch Statement,我试图找到一个使用switch语句的(内置)java方法 为了澄清我的问题,我不是在问如何使用Java switch语句。 我意识到我可以创建自己的方法并将switch语句放入其中 我正在Java中寻找一种方法,它的代码中包含这样的语句 为了进一步澄清我的问题,我想在Java API中找到一个方法: 它使用switch语句 谢谢大家! 下面是源代码中所有提到“switch”的.java文件的列表(大多数文件似乎都在使用switch语句,尽管少数文件似乎只是在注释中讨论) 但是为了回答最初的问题

我试图找到一个使用switch语句的(内置)java方法

为了澄清我的问题,我不是在问如何使用Java switch语句。 我意识到我可以创建自己的方法并将switch语句放入其中

我正在Java中寻找一种方法,它的代码中包含这样的语句

为了进一步澄清我的问题,我想在Java API中找到一个方法: 它使用switch语句


谢谢大家!

下面是源代码中所有提到“switch”的.java文件的列表(大多数文件似乎都在使用switch语句,尽管少数文件似乎只是在注释中讨论)

但是为了回答最初的问题:在众多示例中,这里有一个来自
JLabel.java

    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;
        }
    }
公共字符串getAtIndex(int部分,int索引){
如果(索引<0 | |索引>=getCharCount()){
返回null;
}
开关(部分){
大小写可访问性text.CHARACTER:
试一试{
返回getText(索引,1);
}捕获(错误位置异常e){
返回null;
}
case AccessibleText.WORD:
试一试{
字符串s=getText(0,getCharCount());
BreakIterator words=BreakIterator.getWordInstance(getLocale());
字数.setText(s);
int end=单词。以下(索引);
返回s.substring(words.previous(),end);
}捕获(错误位置异常e){
返回null;
}
case AccessibleText.句子:
试一试{
字符串s=getText(0,getCharCount());
破译迭代器句=
getSentenceInstance(getLocale());
语句.setText(s);
int end=以下句子(索引);
返回s.substring(句子.previous(),end);
}捕获(错误位置异常e){
返回null;
}
违约:
返回null;
}
}

这确实在Java API中。

因此,为它提取src.zip和grep?在库源代码中对其进行grepping也没有帮助?还有,为什么?