DEV Community

Discussion on: Safely accessing lateinit properties in Kotlin

Collapse
 
trevornemanic profile image
Trevor Nemanic • Edited

Reflection has a performance penalty in Java

stackoverflow.com/questions/435553...
From SO: Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.

IMHO, it wouldn't hurt to use lateinit properties judiciously, but relying on them would hurt your performance (eg. looping over a Collection).

Thread Thread
 
rahulchowdhury profile image
Rahul Chowdhury 🕶

Yes, I agree that reflection is slow and overuse of reflection can slow down your application. However, as you said, wise usage of this syntactic sugar won't do much harm.