This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Positions { | |
@JvmStatic | |
@JvmOverloads | |
fun create(x: Int, | |
y: Int = x) = Position.create(x, y) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Position { | |
val x: Int | |
val y: Int | |
fun calculateArea(): Int = x.times(y) | |
companion object { | |
@JvmOverloads |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class PositionBase( | |
override val x: Int, | |
override val y: Int) : Position { | |
final override fun calculateArea(): Int { | |
return super.calculateArea() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class PositionBase : Position |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Position { | |
val x: Int | |
val y: Int | |
fun calculateArea(): Int = x.times(y) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventBus { | |
@JvmName("subscribe") | |
internal fun <T: Event> subscribe(eventType: Class<T>) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reified is not visible from Java | |
class EventBus { | |
inline fun <reified T : Event> subscribe( | |
noinline callback: (T) -> Unit) { | |
// ... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Position { | |
val x: Int | |
val y: Int | |
} | |
// idiomatic in Kotlin | |
pos.x | |
pos.y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun usage() { | |
EventBus().subscribe<Event> { } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T : Event> EventBus.subscribe( | |
noinline callback: (T) -> Unit) { | |
return subscribe( | |
klass = T::class, | |
callback = callback) | |
} |