当前位置: 代码迷 >> 综合 >> java:Cannot refer to a non-final variable tx inside an inner class defined in a different method
  详细解决方案

java:Cannot refer to a non-final variable tx inside an inner class defined in a different method

热度:54   发布时间:2023-12-17 22:22:54.0
final  JTextField tx =  null ;
// 使用匿名内部类,隐式调用外部变量,外部变量需要final修饰。
jb.addActionListener( new  java.awt.event.ActionListener(){
     public  void  actionPerformed(java.awt.event.ActionEvent e) {
     String str = tx.getText();
}