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

zero_coding

08/26/2020, 7:23 PM
Hi all Why do I need parentheses at the end of the following inheritance:
Copy code
class NoInterestsFound : RuntimeException()
c

Casey Brooks

08/26/2020, 7:31 PM
They signify that you’re extending a class. If you omit the parentheses, you’re implementing an interface. Since
RuntimeException
is a class, it is being extended and requires the parentheses as it is effectively calling the superclass constructor
👍 1
t

Tobias Berger

08/26/2020, 7:31 PM
Because
RuntimeException
is a class and you have to call its constructor. It's like calling
super()
in the first line of a Java constructor, kotlin just forces you to do it explicitly.
👆 4
👍 1
as there are no keywords like
extends
and
implements
in kotlin, I'd say it's also very useful as a differentiation between interfaces and superclasses (as @Casey Brooks said)
z

zero_coding

08/26/2020, 7:48 PM
Thanks a lot guys
👍 1
2 Views