3 ms·
I believe he means that very often, type annotations are not necessary to know unambiguously the type of a variable or the return type of a function. For examp
by nrinaudo 12y ago
I believe he means that very often, type annotations are not necessary to know unambiguously the type of a variable or the return type of a function.
For example, in the following Java code:
public String myMethod() { return "hello, world"; }
String myVal = myMethod();
Given that the compiler knows that myMethod cannot return anything but a string, there really should be no need to state it explicitly - it's redundant information. Likewise, myVal can only be of the same type as myMethod's return type.
Languages with type inference get rid of (most of) that redundancy. Take Scala, for example:
def myMethod() = "hello, world"
val myVal = myMethod()