getObjectOrNull

fun getObjectOrNull(obj: Any, fieldName: String): Any?

Get the field object by the name in the object.

Return

field object or null

Parameters

obj

object

fieldName

field name

Throws

if the field is not found

Samples

import com.github.kyuubiran.ezxhelper.ObjectUtils
fun main() { 
   //sampleStart 
   val obj = object {
    val field = "Hello World"
}
val field = ObjectUtils.getObjectOrNull(obj, "field")
println(field) 
   //sampleEnd
}

fun getObjectOrNull(obj: Any, fieldName: String, clazz: Class<*>? = null): Any?

Get the field object by the name in the object.

Return

field object or null

Parameters

obj

object

fieldName

field name

clazz

class where the field is declared (optional, defaults to the class of 'obj')

Throws

if the field is not found

Samples

import com.github.kyuubiran.ezxhelper.ObjectUtils
fun main() { 
   //sampleStart 
   val obj = object {
    val field = "Hello World"
}
val field = ObjectUtils.getObjectOrNull(obj, "field")
println(field) 
   //sampleEnd
}