'How does 'type DoNotCompare [0]func()' prevent comparability in Golang
Per protobuf pragma
`type DoNotCompare [0]func()` DoNotCompare can be embedded in a struct to prevent comparability
I am confused why DoNotCompare could prevent comparability, and try to understand with the following codes. Unfortunately, I am failed. The NonCompare struct seems could be comparability.
type DoNotCompare [0]func()
type NonCompare struct {
DoNotCompare
ii int8
}
type Comparer interface {
Compare(b NonCompare) int
}
func (a NonCompare) Compare(b NonCompare) int {
if a.ii > b.ii {
return 1
}
return 0
}
func main() {
var nc1 = NonCompare{ii: 3}
var nc2 = NonCompare{ii: 5}
nc1.Compare(nc2)
Is there anything am I missing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
