Use case for RuntimeException from package Kotlin

a_local_nobody :

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: enter image description here

Inside the kotlin version of this, there's an entire list of other methods which work the same way :

enter image description here

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 ?

Tenfour04 :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=305157&siteId=1