Why dont languages allow overloading of methods by return value?

前端 未结 8 636
[愿得一人]
[愿得一人] 2021-01-02 08:38

c, java and many other languages do not pay attention to return values.

int   i = func()
float f = func()
int   func() { return 5 }
float func() { return 1.3         


        
8条回答
  •  庸人自扰
    2021-01-02 09:04

    Most languages allow for mixed-mode operations with automatic coercion (e.g. float + int), where multiple interpretations are legal. Without coercion, working with multiple numeric types (short, int, long, float, double) would become very cumbersome; with coercion, return-type based disambigation would lead to hard-to-understand code.

提交回复
热议问题