I'm new to golang and I want to implement an overloaded method something similar to C++ overloading, and my code looks something like this:
type someStruct struct {
val int
some string
}
type object interface {
toByte()
}
// someStruct implementing an object interface
func (s *someStruct) toByte() {
}
func overload(overLoadedObj interface{}) {
switch str := overLoadedObj .(type) {
case string:
fmt.Println("string : ", str)
case int:
fmt.Println("int : ", str)
case object: //* It doesn't come here at all*
fmt.Println("interface obj", str)
}
}
func main() {
overload("hello")
overload(5)
overload(someStruct{val: 5, some: "say"})
}
So the question is:
How to make sure that whoever implements object interface will fall in at case object type ?
Thanks in advance.