官术网_书友最值得收藏!

  • Learn Scala Programming
  • Slava Schmidt
  • 141字
  • 2021-06-10 19:35:44

Type constraints

Type constraints are rules associated with a type. They define a subset of all types that, for example, a variable can have. A type constraint takes the form of lower bound (subtype relation) or upper bound (supertype relation). It is possible to define multiple constraints for a single type. In this case, a type must satisfy both of them. Constraints are defined using the symbols >: (lower, unhappy bound) and  <: (upper, happy bound), and the direction of the sign corresponds to the reversed direction of the arrow on the UML diagram, as shown in the following screenshot:

The type constraints are inclusive, which is why type B represents both the upper and lower bounds. Besides B in our type hierarchy, only A obeys the LOWER type constraint and only  obeys the UPPER constraint.

主站蜘蛛池模板: 安新县| 万山特区| 漳平市| 望城县| 句容市| 抚宁县| 云霄县| 山阴县| 错那县| 山西省| 垫江县| 德令哈市| 永春县| 平乡县| 云安县| 昔阳县| 扎兰屯市| 沾化县| 府谷县| 吉木萨尔县| 深泽县| 高雄市| 庆城县| 永福县| 开阳县| 栾城县| 吉隆县| 始兴县| 淮北市| 陵川县| 新和县| 霍山县| 阿拉善右旗| 滦平县| 东兴市| 福鼎市| 景德镇市| 渝北区| 安福县| 扬州市| 中卫市|