Java – why can’t we overload a method based on the throws exception?

Why can't we overload methods that have the same return type, name, and parameters but have some exceptions thrown? As shown in the figure

public String getAppletInfo(){  }
      public String getAppletInfo() throws Exception{ }

Solution

When you call getAppletInfo () in code, how do you want JVM to select the overload that you want to call? There is no semantic information in a single method call, allowing you to specify the exception it should expect

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>