3 // Copyright 2021 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
15 type Stringer interface {
19 // StringableList is a slice of some type, where the type
20 // must have a String method.
21 type StringableList[T Stringer] []T
23 func (s StringableList[T]) String() string {
24 var sb strings.Builder
29 sb.WriteString(v.String())
36 func (a myint) String() string {
37 return strconv.Itoa(int(a))
41 v := StringableList[myint]{myint(1), myint(2)}
43 if got, want := v.String(), "1, 2"; got != want {
44 panic(fmt.Sprintf("got %s, want %s", got, want))