Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以为整数参数设置一个范围以确保整数值在给定范围之间
method(int @Range(0,9) i)
它从字面上检查参数 i 是否在给定范围之间?
如果要编译时检查,可以使用 Checker Framework 的Index Checker或Constant Value Checker并编写@IntRange注释:
@IntRange
method(int @IntRange(0,9) i) { ... }