Hi all Why do I need parentheses at the end of the...
# getting-started
z
Hi all Why do I need parentheses at the end of the following inheritance:
Copy code
class NoInterestsFound : RuntimeException()
c
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
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
Thanks a lot guys
👍 1