Java : Re: local class
http://d.hatena.ne.jp/odz/20080212/1202842607
名前つきのlocal classは、Javaでメソッド内関数を定義するのに頻出(?)のパターンです。
例えば、渡された文字列の " でクオートされたところだけを処理するような単純なパーサーとかを書くのは、こんな感じ。
class Main { void process (final String txt) { class Parser { int i=-1; void parse () { while (++i < txt.length()){ switch (txt.charAt(i)){ case '"': parseQuote(); break; } } } void parseQuote () { while (++i < txt.length()){ switch (txt.charAt(i)){ case '"': return; } } } } new Parser().parse(); } }