I am trying to interface with TeamCity using Kotlin.
When you convert a project to Kotlin (from .xml) you will have a file called Project.kt which is where you can set all your configurations.
With no editing mine looks like this:
object Project : Project(/* Some Function Literal with Receiver */)
This looks like circular inheritance? There are imports that I am omitting, but surely that wouldn't make that big of a difference? Could the name be interpreted in different ways depending on where it appears in the file?
My mind is interpreting the object signature like this:
Is this circular inheritance or have I missed something big about Kotlin? I have looked here and here and can't seem to find my answer.
Android Dependency Injection using Dagger with Kotlin Inheritance is one of the key features of object-oriented programming which allows user to create a new class from an existing class. Inheritance we can inherit all the features from the base class and can have additional features of its own as well.
In Kotlin, implementation inheritance is regulated by the following rule: if a class inherits multiple implementations of the same member from its immediate superclasses, it must override this member and provide its own implementation (perhaps, using one of the inherited ones).
First, like Java, a Kotlin class can only inherit one superclass, but it can implement multiple interfaces. Kotlin uses the colon character “:” to indicate both inheritance and interfaces' implementation. So, for example, class MyType(…) : SuperType(…) means the MyType class inherits the SuperType class.
In Kotlin we are not allowed to extend multiple superclasses. Multiple-inheritance is achieved by giving concrete functions to interfaces.
Assuming qualified classes other.Project
and my.Project
, you'd have two different classes defined with the same name, in different packages.
Since my.Project
is defined as a Singleton, you cannot extend from it and the actual base class is other.Project
. Kotlin is clever enough to differentiate. If you would try to do the same with a class declaration, you'd get a circular inheritance.
You could even try to force extending from the Singleton explicitly, but then you'll have the error Cannot inherit from a Singleton. So basically this only works well if you imported the right classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With