Android Studio tip 6 — Builder

Federico Palmieri
AndroidPub
Published in
1 min readFeb 28, 2017

--

Let’s see how we can easily implement the builder pattern on Android Studio.

For who doesn’t know what’s the Builder pattern and how to use it, I’ll suggest reading about it in the Effective Java book by Joshua Bloch.

Back to us, imagine a scenario where you have 10 fields in your object. How painful would it be to hand-write the builder for that class? That’s where the InnerBuilder plugin comes in our help!

InnerBuilder

This nice plugin does the hard work for you and it allows you to create a builder copy constructor, define for which fields you want the builder methods, define if you want to use the “with…” notation and more! You can check the repo to get the full list of the supported feature here.

If you have mandatory field then you need to define it final in order to make the plugin working correctly:

Hopefully, this will save you some time in the future!

--

--

Federico Palmieri
AndroidPub

Software engineer. Tech enthusiast, football fan, beer lover.