Removing throws in overriden method, compiler wants a try/catch block when invoking

后端 未结 3 1521
轻奢々
轻奢々 2021-01-20 14:38

I have a subclass and I am overriding the inherited parent method: I am removing the throws clause from the method declaration.

Now, using polymorphism, the my insta

3条回答
  •  囚心锁ツ
    2021-01-20 15:13

    The compiler ses an A which does throw an Exception. If you however told the compiler it's an actual SubB object it will stop complaining

    SubB b = new SubB();
    b.foo();
    

提交回复
热议问题