2 ms·
> You're always free to use a final class with a private constructor as a namespace for static methods. Many classes in the standard library are of this kind, i
by watwut 4y ago
> You're always free to use a final class with a private constructor as a namespace for static methods. Many classes in the standard library are of this kind, including `Math`. It's not ideal (see my next point), but it's a far cry from adding extra object instantiations everywhere.
And you literally gained nothing. You do exact same thing with slightly different syntax.
- sagarm 4y agoA version of Math that had non-static methods instead of static ones would be strictly worse IMO. Extra allocations, extra line noise from instantiations, very likely many users would start keeping Math objects around as local, member, or even static (lol) variables.