4 ms·
Can you elaborate, what redundancy are you talking about?
by LoneWolf 12y ago
Can you elaborate, what redundancy are you talking about?
- nrinaudo 12y agoI 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()
- ufo 12y agoOne example is repeating the class name in the type declaration and in the constructor call: Foo foo = new Foo();