Last active
June 19, 2021 05:41
-
-
Save GabrielBrasileiro/086d9d86209b7f61343be447eeea2921 to your computer and use it in GitHub Desktop.
Reified.kt
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 main() { | |
println(filtrarString<String>()) | |
println(adquirirMetodos<String>()) | |
} | |
inline fun <reified T : Any> adquirirMetodos(): List<String> { | |
return T::class.java.methods.map { it.toString() } | |
} | |
inline fun <reified T : Any> filtrarString(): T? { | |
itens().forEach { | |
if (it is T) { | |
return it | |
} | |
} | |
return null | |
} | |
fun itens() = listOf<Any>(0, "Reified", 1f) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment