Bez popisu

chapter3-others-about-generics.slide 569B

123456789101112131415161718192021
  1. # More on type sets
  2. Qinghe
  3. 21 Jan 2022
  4. ## Both elements and methods in constraints
  5. 约束中可以同时约束元素(具体类型、近似类型、联合类型)和方法。
  6. .code codes/type_sets.go /StringableSignedInteger OMIT/,/StringableSignedInteger OMIT/
  7. 满足这个约束的类型必须满足两个条件:
  8. 1. 底层类型是int/int8/int16/int32/int64类型其中之一
  9. 2. 这个类型必须有`String() string`方法
  10. 要注意:
  11. `'~'`符号是必要的,因为int类型本身没有实现`String() string`方法
  12. ## Composite types in constraints