I was writing some code and was going to throw a RuntimeException
as a default for something, when I noticed that there are two options for RuntimeException
- one from java.lang
and one from kotlin
:
Inside the kotlin version of this, there's an entire list of other methods which work the same way :
So, from my understanding of this, the one from package kotlin
is simply an alias for the java equivalent (correct me if I'm wrong) which leads me to the question :
what is the point of having this alias file and when should you use it over the "standard" java equivalent ? Does this simply save a few imports ?
When using the JDK, these map to JDK classes. When using Kotlin for Javascript, they would map to a specific implementation in the Kotlin Javascript library. Documentation about actual
and expect
here.
To answer your question, if there's a chance of you porting your code to also work on another platform, always use the kotlin.
variant. Otherwise, it doesn't matter.