Is there a way to provide a default toString() to an interface?
john.r.rose at oracle.com
Wed Mar 12 08:02:05 UTC 2014
On Mar 12, 2014, at 12:45 AM, Wang Weijun <weijun.wang at oracle.com> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the compiler-dev