mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 12:33:42 +00:00
Add rudimentary interface support
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user