Java – why can’t we overload a method based on the throws exception?
•
Java
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
二维码