On Tue, Sep 4, 2018 at 9:49 AM, roger peppe <rogpe...@gmail.com> wrote: > > For example, the Stringer contract in the > design doc purports to check that there's a method named String, which > it does not - it could be a function-valued field instead. > > So if you've written something like this: > > func FastString(type T stringer)(x T) string { > switch x.(type) { > case myType: > return x.String() > default: > // Slow path: fall back to fmt. > return fmt.Sprint(x) > } > } > > you might expect that fmt.Sprint will call the String method that's > defined on x, but that's not guaranteed.
That's a good point though note that for a case like this you could of course write contract stringer(x T) { var _ fmt.Stringer = x } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.