Add rudimentary interface support

This commit is contained in:
Ayke van Laethem
2018-04-19 20:30:06 +02:00
parent 850fef9852
commit 3e3c3d259f
3 changed files with 123 additions and 18 deletions
+13
View File
@@ -22,12 +22,25 @@ func main() {
thing := Thing{"foo"}
println("thing:", thing.String())
printItf(5)
printItf(byte('x'))
}
func strlen(s string) int {
return len(s)
}
func printItf(val interface{}) {
switch val := val.(type) {
case int:
println("is int:", val)
case byte:
println("is byte:", val)
default:
println("is ?")
}
}
func calculateAnswer() int {
seven := 7
return SIX * seven