Created
April 9, 2018 21:36
-
-
Save evertheylen/026806a0fcb7844db766884dbfd7deed to your computer and use it in GitHub Desktop.
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
// Some (Java) library: | |
class Context { | |
fun register(cl: SomeClient) { | |
cl.initClient(this) | |
} | |
} | |
abstract class SomeClient { | |
abstract fun initClient(ctx: Context) | |
} | |
// Own program: | |
class OwnClient: SomeClient() { | |
var context: Context? = null | |
override fun initClient(ctx: Context) { | |
context = ctx | |
} | |
fun ownCode() { | |
// Better way of handling context? | |
if (context == null) { | |
// handle this... | |
} else { | |
// can't just use context, since it is a var, have to use context!! everywhere :( | |
println("hello world") | |
} | |
} | |
} | |
fun main(args: Array<String>) { | |
val ctx = Context() | |
var cl = OwnClient() | |
ctx.register(cl) | |
cl.ownCode() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment