3 ms·
In practice, the return type is often obvious. You can write: val foo = new MyReallyLongUglyFactoryClass() instead of: MyReallyLongUglyFactoryClass foo =
by MajimasEyepatch 4y ago
In practice, the return type is often obvious. You can write:
val foo = new MyReallyLongUglyFactoryClass()
instead of:
MyReallyLongUglyFactoryClass foo = new MyReallyLongUglyFactoryClass()
And you never have to use type inference. If you have a method where the return type isn't as obvious, you can always annotate it explicitly:
val foo: Int = doSomeThing()
Do people exercise judgement about when to make the type explicit? Eh, depends on the team. But if you combine type inference with established conventions in a particular codebase (e.g. I/O calls always return IO[Foo]), you will rarely be left wondering what the type of something is.