Is there a way to provide a default toString() to an interface?

John Rose john.r.rose at
Wed Mar 12 08:02:05 UTC 2014

On Mar 12, 2014, at 12:45 AM, Wang Weijun < at> wrote:

> I do not want to rename it to getString() and let all child classes call it in their toString().

It is probably best to define a *static* method to hold the default implementation, so that the only candidate for overriding is toString itself.

See MethodHandleInfo and InfoFromMemberName (in java.lang.invoke) for one example of this pattern.

— John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the compiler-dev mailing list