![微信图片_20190510201635.png](https://static.studygolang.com/190510/1db811c69447a932e449ea63a12dc7c4.png)
package main
import(
"fmt"
)
type USB interface{
name()string
Connect()
}
type Phoneconnecter struct{
name string
}
func (pc Phoneconnecter)name()string{
return pc.name
}
func (pc Phoneconnecter)Connect(){
fmt.Println("Connect:",pc.name)
}
func main(){
var a USB
a:=Phoneconnecter{"Phoneconnecter"}
a.Connect()
Disconnect(a)
}
func Disconnect(usb USB){
fmt.Println("Disconnected.")
}
# command-line-arguments
.\2.go:15:6: type Phoneconnecter has both field and method named name
.\2.go:23:3: no new variables on left side of :=
.\2.go:23:3: Phoneconnecter.name is a field, not a method
.\2.go:23:3: cannot use Phoneconnecter literal (type Phoneconnecter) as type USB in assignment:
Phoneconnecter does not implement USB (missing name method)
[Finished in 0.3s]
有疑问加站长微信联系(非本文作者))