[generics] avoid dummy getter by interface with fields

85 views
Skip to first unread message

nvcnvn

unread,
Jun 17, 2020, 9:54:44 PM6/17/20
to golang-nuts
Since Go will need to modify interface with new type list anyway. Is it good if we can do this:
```
type Weighter interface {
    Weight int
}

func CompareWeight(type T Weighter) (a, b T) bool {
    return a.Weight < b.Weight
}

```

Instead of:

```
type Weighter interface {
    GetWeight() int
}

func CompareWeight(type T Weighter) (a, b T) bool {
    return a.Weight() < b.Weight()
}

```

Reply all
Reply to author
Forward
0 new messages