Last active
          June 19, 2021 05:45 
        
      - 
      
- 
        Save GabrielBrasileiro/aa9382a048500cd34b58410adfaddf53 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::class.java)) | |
| println(adquirirMetodos(String::class.java)) | |
| } | |
| fun <T : Any> adquirirMetodos(clazz: Class<T>): List<String> { | |
| return clazz::class.java.methods.map { it.toString() } | |
| } | |
| fun <T : Any> filtrarString(clazz: Class<T>): T? { | |
| itens().forEach { | |
| if (clazz.isInstance(it)) { | |
| @Suppress("UNCHECKED_CAST") | |
| return it as T | |
| } | |
| } | |
| 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