Last active
February 21, 2019 03:55
-
-
Save rming/87e7a4c47a2231142b25d3de4ca3d2f3 to your computer and use it in GitHub Desktop.
go test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
type AppInterface interface { | |
run() *App | |
} | |
type App struct { | |
attr string | |
} | |
func (self *App) run() *App { | |
self.attr = "abc" | |
return self | |
} | |
func f(app AppInterface) { | |
fmt.Println(app) | |
} | |
func main() { | |
var app AppInterface = new(App) | |
var app1 *App = new(App) | |
var app2 App | |
fmt.Println(reflect.TypeOf(app), app) | |
fmt.Println(reflect.TypeOf(app1), app1) | |
fmt.Println(reflect.TypeOf(app2), app2) | |
app.run() | |
app1.run() | |
app2.run() | |
f(app) | |
f(app1) | |
f(&app2) | |
fmt.Println(app.(*App).attr) | |
fmt.Println(app1.attr) | |
fmt.Println(app2.attr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment