https://play.golang.org/p/0U5_YrAYW7o
The comments explain a lot in the code.
Im trying to make a function that returns the type of animal, and pass that function as a parameter. There since to be a problem with type conversion.
The three send functons are sending me the info i need.
https://play.golang.org/p/0U5_YrAYW7o
2 Likes
@JustinObanor I made a couple of corrections to your code here: https://play.golang.org/p/uiQuC0LBtit
Your type conversion was working just fine. It was that your function was expecting a return type of Animalizer
, but you were already accessing the typeOfAnimal()
. This method returns a string
type.
//trying to make a function that gives me the type of animal from the first struct. Will make others later
//error is from here. Not sure how to return the typeOfAnimal
a1 := func() Animalizer {
var a Animalizer
switch a.(type) {
case Animal1:
return a.(Animal1).typeOfAnimal()
}
}
2 Likes
Yeah, but the things that im trying to return the Animalizer interface, and not a string…can i make that possible?
2 Likes
Yes, just take off typeOfAnimal()
method off of a.(Animal1).typeOfAnimal()
.
3 Likes
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.