Member-only story

How to quickly de-lombok a val in IntelliJ IDEA

Forketyfork
3 min readMar 13, 2020

--

Image by Anrita1705 from Pixabay

Many of my projects are still on Java 8, and I use Lombok extensively. I especially like the val keyword which is similar to Java 11’s local variable type inference, which is otherwise inaccessible in Java 8. Instead of saying:

String string = "example";

with Lombok, I often say:

val string = "example";

This may not save too many keystrokes in this case, but if the class names get long, val can really simplify the code. Unfortunately, sometimes it gets in your way, and you want to revert it to the old ways.

Even if you have the lombok plugin in IntelliJ IDEA, that supports de-lomboking of annotations, there’s no quick way to de-lombok the val keyword. So this is the easiest way I could find to do it — in just 4 keystrokes.

Suppose you have this line and you want to replace val with the actual variable type — String in this case. (Once again, in this case it’s easier to just write String instead of val, but imagine the expression is much more complicated, and the type name is lengthy.)

Now you put your cursor on the beginning of the string variable name and hit Alt+Backspace (or Option+Backspace, for Mac users) to remove the val keyword:

--

--

Forketyfork
Forketyfork

Written by Forketyfork

Software developer @ JetBrains CodeCanvas. I write technical how-to articles and occasional rants on software development in general. Opinions are my own.

No responses yet