而后我写了一些测试代码:
dept1 :=
    Dept{
        name:     "MySohu",
        building: "Internet",
        floor:    7}
switch v := interface{}(dept1).(type) {
case DeptModeFull:
    fmt.Printf("The dept1 is a DeptModeFull.\n")
case DeptModeB:
    fmt.Printf("The dept1 is a DeptModeB.\n")
case DeptModeA:
    fmt.Printf("The dept1 is a DeptModeA.\n")
default:
    fmt.Printf("The type of dept1 is %v\n", v)
}
deptPtr1 := &dept1
if _, ok := interface{}(deptPtr1).(DeptModeFull); ok {
    fmt.Printf("The deptPtr1 is a DeptModeFull.\n")
}
if _, ok := interface{}(deptPtr1).(DeptModeA); ok {
    fmt.Printf("The deptPtr1 is a DeptModeA.\n")
}
if _, ok := interface{}(deptPtr1).(DeptModeB); ok {
    fmt.Printf("The deptPtr1 is a DeptModeB.\n")
}
打印出的内容

相关文章:

  • 2021-07-01
  • 2021-09-19
  • 2021-10-20
  • 2021-08-23
  • 2021-12-04
  • 2021-10-01
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2021-12-24
  • 2021-08-06
  • 2021-10-06
  • 2022-01-11
相关资源
相似解决方案