2 ms·
> I hate having to say everything twice. Types force me to do that Thats just because most OO languages OP uses don't have powerful type inference. Sure, type
by ufo 12y ago
> I hate having to say everything twice. Types force me to do that
Thats just because most OO languages OP uses don't have powerful type inference. Sure, type inference is tricky in languages with subtyping but it certainly doesn't need to be verbose and redundant like it is in Java.
- LoneWolf 12y agoCan 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();