This file contains 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
@FragmentScope | |
@Component( | |
dependencies = [ApplicationComponent::class], | |
modules = [ExampleModule::class] | |
) | |
interface ExampleComponent { | |
fun inject(fragment: ExampleFragment) | |
} |
This file contains 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 interface Factory<T> { | |
fun create(): T | |
} | |
fun <T> createInstance(factory: Factory<T>): T { | |
return factory.create() | |
} | |
fun main() { | |
val instance = createInstance(Factory { |
This file contains 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 SomeClass { | |
fun doTask() { | |
for (i in 1..10) { | |
println(i) | |
} | |
} | |
} | |
fun <T> createClassInstance(someClass: Class<T>): T{ | |
return someClass.getDeclaredConstructor().newInstance() |
This file contains 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 LRUCache(private val capacity: Int) { | |
inner class Node( | |
val key: Int, | |
val value: Int, | |
var next: Node? = null, | |
var prev: Node? = null | |
) | |
private val cache = mutableMapOf<Int, Node>() |