Allow interface default toString implementation
Brandon Mintern
mintern at everlaw.com
Wed Jun 11 23:56:41 UTC 2014
On Tue, Jun 10, 2014 at 6:12 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> On Tue, Jun 10, 2014 at 5:43 PM, Brandon Mintern <mintern at everlaw.com>
> wrote:
>
> > public class Object implements Objects {
>
> `Object` is supposed to be the root type of everything. It's too odd
> if it has a super type.
>
> Even if we do want to allow `toString()` default impl on interfaces,
> it'll be much easier to simply special-case it, instead of going
> through this exercise.
>
Fair enough. I would argue that the opposite is weird, that an interface
can make use of class (rather than interface) methods like getClass() in
default implementations. It's inconsistent with the rest of the language,
where interface methods can never use class methods.
That said, this is a problem only in principle, not in practice, so I don't
have any qualms about your suggestion.
However, the crux of the matter, I think, is to avoid depending on
> `toString()`.
I hope this isn't a serious suggestion. We don't rely on `toString()`
directly -- this is the entire point of creating our own interface method
like `toJson()` instead of assuming a class will implement `toString()` to
do what we'd like. But live debuggers, logging systems, even Java's
built-in String formatting and concatenation use `toString`, so it's not
like it can just be avoided.
More information about the lambda-dev
mailing list