can anonymous inner classes extend?

前端 未结 2 1518
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-20 09:29

I want to create an anonymous inner class that extends another class.

What I want to do is actually something like the following:

for(final e:lis         


        
2条回答
  •  礼貌的吻别
    2020-12-20 09:32

    extends keyword only allow using in class definition. Don't allow in anonymous class.

    Anonymous class define is: class without any name and don't use after declaration.

    We have to correct your code as following(for example):

    Callable test = new Callable()
    {
        @Override
        public String call() throws Exception
        {
            return "Hello World";
        }
    };
    

提交回复
热议问题