I have to verify if all lateinit fields of a class...
# reflect
b
I have to verify if all lateinit fields of a class have been initialized. Currently I'm doing this:
Copy code
fun DtoStructure.validateAllLateinit(): Boolean {
	for (method in javaClass.methods) {
		if (method.name.startsWith("get")) {
			try {
				method(this)
			}
			catch (exception: InvocationTargetException) {
				if (exception.cause is UninitializedPropertyAccessException) {
					return false
				}
			}
		}
	}

	return true
}
... which feels weird to me. I just got "lucky" that Kotlin fields are converted into getter/setters when compiled to bytecode, and I'm using this fact as a workaround. Anyone knows something better? Maybe using the Reflection API of Kotlin, and not Java?