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

  • 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.

主站蜘蛛池模板: 焦作市| 曲沃县| 固安县| 柳河县| 临沭县| 桦甸市| 清苑县| 读书| 古浪县| 瑞丽市| 安义县| 调兵山市| 天峨县| 泰宁县| 海淀区| 栖霞市| 蒙自县| 云霄县| 神木县| 铜陵市| 台中市| 丹棱县| 长垣县| 鄂温| 绿春县| 英吉沙县| 新密市| 洪江市| 嘉黎县| 拜泉县| 开平市| 于田县| 彭水| 东辽县| 无锡市| 金寨县| 宜章县| 安顺市| 吐鲁番市| 崇文区| 扶风县|