HI, Go newbie here... not sure if this is a dumb question or not :)
I have a simple program:
package main
import "fmt"
type any interface{}
type myInt int
func plus(a, b any) any { return a.(myInt) + b.(myInt) }
func main() {
s := plus(myInt(3), myInt(2))
fmt.Printf("%v, %T\n", s, s)
}
Output:
5, main.myInt
Why does func plus return a myInt? Why isn't a cast needed, ie:
func plus(a, b any) any { return myInt(a.(myInt) + b.(myInt)) }
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 [email protected].
For more options, visit https://groups.google.com/d/optout.