package codesample.kotlin.sandbox.classes


interface One {
    fun doSomething() {
        println("One flying!")
    }
}

interface Two {
    fun doSomething() {
        println("Two flying!")
    }
}

/**
 * If both interfaces have a method with the same signature, you ccan override it once.
 * You can also call respective super methods if required
 */
class OneTwoImplementor: One, Two {
    override fun doSomething() {
        super<One>.doSomething()
        super<Two>.doSomething()
    }
}


fun main(args: Array<String>) {
    val one: One = OneTwoImplementor()
    val two: Two = OneTwoImplementor()

    one.doSomething()
    two.doSomething()
}
package codesample.kotlin.sandbox.classes


interface One {
    fun doSomething() {
        println("One flying!")
    }
}

interface Two {
    fun doSomething() {
        println("Two flying!")
    }
}

/**
 * If both interfaces have a method with the same signature, you ccan override it once.
 * You can also call respective super methods if required
 */
class OneTwoImplementor: One, Two {
    override fun doSomething() {
        super<One>.doSomething()
        super<Two>.doSomething()
    }

    /**
     * Kotlin's way to static methoods is companion objects!
     */
    companion object {
        fun behaveLikeStaticButItsNot() {
            println("I'm not actually static")
        }
    }
}


fun main(args: Array<String>) {
    val one: One = OneTwoImplementor()
    val two: Two = OneTwoImplementor()
    val oneTwo: OneTwoImplementor = OneTwoImplementor();

    one.doSomething()
    two.doSomething()
    oneTwo.doSomething()


    println(one.yetAnotherInterfaceFunction())
    println(oneTwo.yetAnotherInterfaceFunction())
    OneTwoImplementor.behaveLikeStaticButItsNot()
    // two.yetAnotherInterfaceFunction() DOESN'T WORK!

}

/**
 * This is called extensions. We add yet another function to interface, and all classes implementing
 * this interface can now use this function. Note: Classes can not override this function
 */
fun One.yetAnotherInterfaceFunction() : String {
    return "another interface function"
}
Add kotlin object/function extension example
Add kotlin object/function extension example

aquatir/remember_java_api,aquatir/remember_java_api,aquatir/remember_java_api,aquatir/remember_java_api