Wie wird ein Typalias in Go umgewandelt?
Sehendieser Spielplatz Schnipsel.
Relevanter Code:
type somethingFuncy func(int) bool
func funcy(i int) bool {
return i%2 == 0
}
var a interface{} = funcy
func main() {
_ = a.(func(int) bool) // Works
fmt.Println("Awesome -- apparently, literally specifying the func signature works.")
_ = a.(somethingFuncy) // Panics
fmt.Println("Darn -- doesn't get here. But somethingFuncy is the same signature as func(int) bool.")
}
Die erste Besetzung funktioniert, indem der Typ explizit deklariert wird. Aber die zweite Besetzung gerät in Panik. Warum? Gibt es eine saubere Möglichkeit, zu einer längeren Funk-Signatur zu wechseln?