Is it possible to restrict Int by creating something like PositiveInt and have compile-time checks in Scala?

后端 未结 4 1192
失恋的感觉
失恋的感觉 2021-01-07 18:16

Is it possible to create a restricted Int such as PositiveInt and have compile-time checks for it? In other words is it possible to define a method such as:

4条回答
  •  甜味超标
    2021-01-07 18:57

    This kind of thing is called dependent typing, and no, it's not available in Scala.

提交回复
热议问题