Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 667 Bytes

UseRequire.md

File metadata and controls

25 lines (16 loc) · 667 Bytes

Pattern: Missing use of require

Issue: -

Description

Kotlin provides a much more concise way to check preconditions than to manually throw an IllegalArgumentException.

Example of incorrect code:

if (value == null) throw new IllegalArgumentException("value should not be null")
if (value < 0) throw new IllegalArgumentException("value is $value but should be at least 0")

Example of correct code:

requireNotNull(value) {"value should not be null"}
require(value >= 0) { "value is $value but should be at least 0" }

Further Reading