Java Thread: Run method cannot throw checked exception

前端 未结 6 1952
名媛妹妹
名媛妹妹 2020-12-05 00:37

In Java thread, the \'run\' method cannot throw a \'checked exception\'. I came across this in the Core Java (vol 1) book. Can someone please explain the reasoning behind i

6条回答
  •  感动是毒
    2020-12-05 01:27

    The more obvious solution to the previous answers is that if you throw a checked exception, you are not correctly implementing run() as specified in the runnable interface.

    It won't even compile:

    run() in TestClass cannot implement run() in java.lang.Runnable; 
    overridden method does not throw java.lang.Exception  
    

提交回复
热议问题