Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ) {}
like image 659
Basil Bourque Avatar asked Oct 30 '25 05:10

Basil Bourque


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
like image 60
MartinBG Avatar answered Nov 01 '25 19:11

MartinBG