Intellij format java functional interfaces in one line
Answered
I would like to write my code like this:
public class Test {
class A {}
class B {}
interface ABMapper { B map(A a);}
B map(A a, ABMapper mapper) {return mapper.map(a);}
@org.junit.jupiter.api.Test
public void test() {
map(new A(), (a) -> new B());
}
}
But when I format it in Intellij it expands the interface definition. I am able to configure it to keep simple methods in one line, but not interfaces. Does anyone know a way to do that?
I try to achieve a level of readability similar to Kotlin in which I can use typealias to declare in a single line the type of a lambda.
class A
class B
typealias ABMapper = (A) -> B
fun map (a: A, mapper: ABMapper): B = mapper(a)
fun main() {
map(A(), {_ -> B()})
}
Please sign in to leave a comment.
“Settings | Editor | Code Style | Java | Simple classes in one line” will work for simple (empty) classes and interfaces like
but the rest is not considered as simple.