Auto-format a Java record in a single line in IntelliJ?

Viewed 332

IntelliJ 2021.1 adds support for Java 16. And Java 16 adds the new feature of records.

When I define a record locally in IntelliJ 2021.1, the formatting command results in this format:

record Grid(int[] array , int count)
{
}

Is there a way in the auto-formatting rules to keep a record definition to a single line rather than line-wrapping the empty curly braces?

➥ What I want:

record Grid(int[] array , int count) {}

I also want SPACE character before and after each of the parentheses. But the auto-formatting rules already cover that; just seems broken for records. I assume that will be fixed eventually.

What I really want:

record Grid ( int[] array , int count ) {}
1 Answers

Here is one way to achieve that formatting:

Settings -> Editor -> Code Style -> Java, Wrapping and Braces tab

Keep when reformatting section

  • deselect Line breaks
  • select Simple classes in one line enter image description here
Related