Access outer anonymous class from inner anonymous class

前端 未结 4 1540
孤城傲影
孤城傲影 2021-02-12 23:25

I\'m just curious. Is there a way to access parent in anonymous class that is inside another anonymous class?

I make this example create a JTable subclass

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-12 23:53

    Unfortunately, you will have to give a name to the outer anonymous class:

    public class Test{
    
        public static void main(String args []){
    
            class Foo extends JTable {
    
                @Override
                public void changeSelection(
                    final int row, final int column,
                    final boolean toggle, final boolean extend) {
    
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            Foo.super.changeSelection(row, column, toggle, extend); 
                            //more code here
                        }
                    });
                }
            };
    
            JTable table = new Foo();
    
        }//end main
    
    }//end test 
    

提交回复
热议问题