Skip to content

Instantly share code, notes, and snippets.

@FilipeLipan
Created December 14, 2017 12:36
Show Gist options
  • Save FilipeLipan/47022778cef0f2c2a3e8b2803b4ad792 to your computer and use it in GitHub Desktop.
Save FilipeLipan/47022778cef0f2c2a3e8b2803b4ad792 to your computer and use it in GitHub Desktop.
reflection example
var bundle = Bundle()
bundle.putString("este é um teste com bundles", "this a call to all my past resignations")
bundle.putInt("quantidade de cupons", 1)
bundle.putLong("", 1)
val userProperty = UserProperty(name = "fil", email = "test", extra = bundle);
for (prop in UserProperty::class.memberProperties) {
prop.get(userProperty)?.let {
if(prop.returnType.jvmErasure.isSubclassOf(Bundle::class)){
(prop.get(userProperty) as Bundle).keySet().forEach {
val objectInsideTheKey = (prop.get(userProperty) as Bundle).get(it)
Log.d("${it} = ${objectInsideTheKey.toString()}", "teste")
}
}else{
Log.d("${prop.name} = ${prop.get(userProperty)}", "teste")
}
}
}
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment