On Thu, Jan 5, 2017 at 5:29 PM, hui zhang <fastfad...@gmail.com> wrote: > > How can I compare the interface ? > I want to implement a generic function. > the <= >= report error in this code > > func InRange(a, b, c interface{}) bool { > if c >= a && c <= b { > return true > } else { > return false > } > }
You can only compare interface values for equality. To compare for ordering you need to use a type assertion or type switch to some type that supports ordering. Or if, for example, you know that the values contain signed integers, you could use reflect.ValueOf(a).Int(). Ian -- 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.