Friday, February 9, 2018

Killing View Boilerplate with Kotlin

"I hate boilerplate with a passion"
- Developers and the anti-boiler lobby.

Last year I started using Kotlin to write my Android projects. I quickly fell in love with the succinct and expressive syntax, and in no time at all, I started converting Java code to Kotlin. In the process of writing view classes I found a cleaner way to use Delegated Properties to keep my UI in sync with my views' properties.

With the power of Delegated Properties I was able to invalidate my views whenever their properties were mutated. Good-bye to the lines of boilerplate setters for each field in my Java view! I did some searching and haven't seen any similar snippets online, so I've posted up the class with a README.

Intrigued? Check out the embedded gist below,  with further description and usage instructions on github. If you like what you see, leave a star!

Image created by: Physique555, and shared under Creative Commons 4.0


Post a Comment