For example, we can return any on the interface like this:
type AnyFunc interface {
Execute() any
}
type MyStruct struct {
Value int
}
func (m MyStruct) Execute() any {
return m.Value
}
My understanding is to use the return any you would still need to do a run time type check. What is the functional difference from interface{} then?
What is actually returned at runtime? Like with interface{}, I can expect a value pointing the concrete type, and then type /casting checking works like it does in Java (although I don't know how that would work with go's primitives). But then what is returned with the any type?
If you say it's whatever the underlying type is, then how does the compiler know how much memory to allocate for the object? Only way it could do that is it knew the the type of the object ahead of time. If it knows the type of the object ahead of time, then why do we need a runtime type check.