https://play.golang.org/p/0U5_YrAYW7o


(Justin) #1

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


(phoenix coder) #2

@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()
		}
	}

(Justin) #3

Yeah, but the things that im trying to return the Animalizer interface, and not a string…can i make that possible?


(phoenix coder) #4

Yes, just take off typeOfAnimal() method off of a.(Animal1).typeOfAnimal().


(system) closed #5

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.