バリデーションを型システムへ移す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% の行カバレッジ + 95% の PIT ミューテーションスコア
- 正直なところ: 1人プロジェクト、JMH ベンチマークなし、Jackson/
@Validブリッジなし
まだコメントはありません。