Reputation: 11377
Is there a Go interface in the standard library with:
String() string
?
(Similar to how Java has toString() on java.lang.Object)
Perhaps I just didn't search enough but I didn't see one. Wanted to use one that already exists rather than than making my own (though I guess it really makes no difference with Go's type system).
Upvotes: 5
Views: 992
Reputation: 19388
fmt.Stringer
is what you're after.
type Stringer interface {
String() string
}
Upvotes: 10
Reputation: 4359
The closest thing I've seen to Java's toString
is fmt#Stringer.
Upvotes: 4