Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
–
In
Kotlin
, unlike
Java
, assertions can be enabled/disabled only on top-level, i.e. by specifying
-ea
option to JVM.
Behind the scenes,
assert()
in Kotlin is a function, defined in
AssertionsJVM.kt
file.
ENABLED
variable in the
_Assertions
object is used to determine if assertions are enabled.
@PublishedApi
internal object _Assertions {
@JvmField @PublishedApi
internal val ENABLED: Boolean = javaClass.desiredAssertionStatus()
The ENABLED
variable is assign to true
if assertions enabled for the _Assertions
class.
As a consequence, to turn on asserts in Kotlin they have to be enabled in JVM for
all classes -ea
or one particular class -ea:kotlin._Assertions
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.