妥当性検証を型システムへ移すJavaライブラリ(123種類の事前定義型)
(github.com/JunggiKim)Java Refined は、String や int の代わりに NonBlankString、PositiveInt のような事前定義済みの refined 型を使い、検証をシグネチャへ移す ライブラリです。
// Before
void createUser(String name, int age, List<String> roles) {
if (name == null || name.isBlank()) throw new IAE("name");
if (age <= 0) throw new IAE("age");
if (roles == null || roles.isEmpty()) throw new IAE("roles");
}
// After
void createUser(NonBlankString name, PositiveInt age, NonEmptyList<String> roles) { }
- import してすぐ使える 123種類 の事前定義型(VAVR/Arrow はパターンのみ提供)
NonEmptyList<T>がList<T>を 直接実装 — アンラップ不要- ランタイム依存ゼロ · Java 8+ · MIT · Maven Central · Kotlin 拡張モジュールは別途提供
- 行カバレッジ 100% + PIT ミューテーションスコア 95%
- 正直なところ: 1人プロジェクト、JMH ベンチマークなし、Jackson/
@Validブリッジなし
まだコメントはありません。