I have a weird problem. At least, I'm not used to see this happening in
other languages, so hence my question :)
I have a function, which returns a *[]interface{}*, and in the end of that
function, if the slice is empty, I would like instead to return *nil*. The
problem is, I'm not getting *nil* in the caller function. I'm placing
example code:
func getChildren(paramStuff string) []interface{} {
var values []interface{}
// Do Stuff
if len(values) == 0 {
fmt.Println("Returning nil")
return nil
}
return values
}
func stuff() {
fmt.Printf("%+v", getChildren("params"))
}
The output of this code, is:
*Returning nil[]*I was expecting to have *nil* as a return value, instead
of an empty array. Is this expected behaviour?
Thanks!
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.