https://kotlinlang.org logo
#getting-started
Title
# getting-started
o

oday

07/16/2021, 6:16 PM
how exactly do I use
assert()
?
assert(1 == 1, { "Equal" })
shows nothing in the console
where do I check the status of this flag?
y

Youssef Shoaib [MOD]

07/16/2021, 6:20 PM
It's the exact opposite actually. Assert prints the message when the condition is
false
o

oday

07/16/2021, 6:20 PM
ah, excuse me I can’t read
ok so just tried again,
Copy code
assert(1 == 2, {"not true"})
nothing printed still
z

Zun

07/16/2021, 7:16 PM
The docs: Throws an AssertionError calculated by lazyMessage if the value is false and runtime assertions have been enabled on the JVM using the -ea JVM option.
👍🏻 1
e

ephemient

07/16/2021, 8:27 PM
Kotlin's assert is missing Java features too: https://youtrack.jetbrains.com/issue/KT-22292
o

oday

07/16/2021, 8:30 PM
yea was just testing it, not looking to rely on it for anything serious at the moment
e

ephemient

07/16/2021, 8:31 PM
given that, might as well use `check`/`require` (or their `*`NotNull shortcuts)
2 Views