This page is no longer maintained — Please continue to the home page at

Consistency for parentheses on toString in the Scala library?

No replies
Joined: 2011-11-24,
User offline. Last seen 42 years 45 weeks ago.

I use IntelliJ Idea and am grateful for its inspections, one of which
warns about overriding empty-parens methods without parentheses and
vice versa. On toString, however, it is difficult to avoid getting
your code flagged since some library functions use empty-parens (e.g.
FunctionN) and some no parens (e.g. Iterator). The inspections seem to
regard whatever the next parent type does as the law and flag any
aberrations. In general this is a great feature, but for toString the
inconsistency results in a constant guessing game and makes it
impossible to achieve consistency in your own code (say, standardizing
on no-parens because one avoids mutation and side-effects) if you
don't want to be hectored by inspections.

My question is: is there are reason for this apparent inconsistency in
the Scala library, or would it make sense to submit tickets (e.g.
flagging all toStrings that are empty-parens) to help to clean this up
over time?

There is a somewhat related thread on StackOverflow that seems to
point in the direction that in general it may be desirable to
standardize on empty-parens for toString, unless there are special
cases that warrant an exception:

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland