Implement interfaces on the string type

This commit is contained in:
Ayke van Laethem
2018-04-20 22:42:43 +02:00
parent fc2eee4ee8
commit 217c48f933
2 changed files with 24 additions and 2 deletions
+3
View File
@@ -24,6 +24,7 @@ func main() {
println("thing:", thing.String())
printItf(5)
printItf(byte('x'))
printItf("foo")
}
func strlen(s string) int {
@@ -36,6 +37,8 @@ func printItf(val interface{}) {
println("is int:", val)
case byte:
println("is byte:", val)
case string:
println("is string:", val)
default:
println("is ?")
}