3 ms·
> it's an overload and a typecast. No, in Scala there is no typecast in that example. Everything is an object in Scala and the + method in String class accepts
by hrjet 13y ago
> it's an overload and a typecast.
No, in Scala there is no typecast in that example. Everything is an object in Scala and the + method in String class accepts an object as parameter.
There is some auto-boxing happening under the hoods but that is not type-casting.
- chilldream 13y agoYou start with an integer and end up with a string. The intermediate steps required to get from one to the other aren't particularly relevant to the point I was making.
- Fiadliel 13y agoThe string concatenation API for Java IS terrible, but see modersky's post for the reasoning. Just don't mistake a bad API for some kind of belief that Scala in general idly converts between types. The weakest point is APIs that use methods defined in java.lang.Object (e.g. toString and equals); they can universally use these methods without restricting the type. Note that if you define a type as a knowledge of what actions can be performed on an object, then no type safety has been lost; toString() is universally available, though it may not do exactly what you want.