Java重载和返回类型没有关系吗?

dinosaurain 2004-07-25 01:27:59
我看到书上写的不同的返回类型可以进行重载的 啊
为什么写出来程序确不能呢???
...全文
240 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shangqiao 2004-07-25
  • 打赏
  • 举报
回复
想一想这种情况:
int ff();
double ff();
现在有代码:
ff();
你能决定他是调用哪一个方法嘛,你都不能,电脑怎么又能!返回值是执行完方法体时才得到的,这时才知道他的类型,但是这是果,怎么能够由果推因呢?逻辑不相符.
不仅仅返回值不行,还有异常也一样,因为异常是返回类型的特殊形式而已,所以也是不能根据它重载的
sboom 2004-07-25
  • 打赏
  • 举报
回复
仅仅只是返回类型不同,并不是重载
Jane000 2004-07-25
  • 打赏
  • 举报
回复
仅仅只是返回类型不同,并不是重载
registered 2004-07-25
  • 打赏
  • 举报
回复
返回类型跟 overload 毫无关系...
umbrella1984 2004-07-25
  • 打赏
  • 举报
回复
重载的条件
必须修改参数列表
可以修改返回类型
仅单独使用返回类型不能辨别是调用哪个方法
gameboy999 2004-07-25
  • 打赏
  • 举报
回复
Overloading

1.Signature has to be different. Just a difference in return type is not enough.
Accessibility may vary freely.
2.Exception list may vary freely.
3.Just the name is reused. Methods are independent methods. Resolved at compile-time based on method signature.
4.Can call each other by providing appropriate argument list.
5.Methods can be static or non-static. Since the methods are independent, it doesn’t matter. But if two methods have the same signature, declaring one as static and another as non-static does not provide a valid overload. It’s a compile time error.
6.There’s no limit on number of overloaded methods a class can have.

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧