[問題] Anonymous inner class
現在有一段 code 長這樣:
JButton button = new JButton();
button.addMouseListener( new MouseAdapter() {
public void mouseClicked( MouseEvent e ) {
new Thread( new Runnable() {
@Override
public void run() {
( ( JButton )e.getSource() ).setText( "..." );
}
} ).start();
}
} );
然後 ... 它就說 e 要是 final 才可以
我只是很單純地想要讓 inner classes 可以拿到上層的引數
請問有好的做法嗎? (不會要用 static field 吧?)
--
自High筆記(半荒廢)
http://legnaleurc.blogspot.com/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.71.230.153
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1 之 3 篇):