package learn
type A struct {
}
type B struct {
}
type Tasks struct {
Name string
ToSt Te
}
type Te interface{
Tes()
}
func (s *A)Tes() {
}
func (s *B)Tes() {
}
func TT() {
var1 := Tasks{Name: "s", ToSt: A{}}
}
1
rrfeng 2021 年 3 月 11 日
首先你这也不是 map 呀
可以用 interface,不过不要用空 interface |
2
rekulas 2021 年 3 月 11 日
ToSt 改成 interface 不就可以么
|
3
lewinlan 2021 年 3 月 11 日 &A{}即可。
因为 A 没有实现接口,*A 实现了。 |
4
unixeno 2021 年 3 月 11 日 via Android
map[string]interface{}
|
5
yrj 2021 年 3 月 12 日 via iPad
三楼正解
|
6
ly020044 2021 年 3 月 12 日
3 楼没毛病,因为你 A, B 都是用指针对象实现的接口
|
7
sherlockwhite 2021 年 3 月 12 日
package main
type A struct { } type B struct { } type Te interface{ Tes() } type Tasks struct { Name string ToSt Te } func (s *A) Tes() { } func (s *B) Tes() { } func TT() { var test A var1 := Tasks{Name: "s", ToSt: &test} } |
8
sherlockwhite 2021 年 3 月 12 日
3 楼正解
|