How can I make IntelliJ fold variable types?
Used for languages that provide type inference (C ++, Scala). I find code like this hard to read:
ClassWriter classWriter = new ClassWriter(0);
when the type is repeated. Is there a way to get IntelliJ to dump the type of the variable so that I can read and write it like this:
var classWriter = new ClassWriter(0);
but it actually saves it to disk how ClassWriter classWriter = new ClassWriter(0);
?
source to share
The Advanced Java Folding plugin (from JetBrains) adds, among other things, folding for variable declarations.
https://plugins.jetbrains.com/idea/plugin/9320-advanced-java-folding
source to share
No, you cannot do this, and this is probably not a good idea for the following reason.
With java, it is common to create a concrete implementation type and refer to it using an abstract type.
For example:
List<String> myList = new ArrayList<String>();
In this case, if you could just write var myList = new ArrayList<String>();
- what type myList
is it really? Is it List<String>
or ArrayList<String>
?
Strong typing is central to java and the example above illustrates why.
Java 7 will improve a little when the readability of parameterized types can use diamond:
List<String> myList = new ArrayList<>();
Anyway, I would suggest just giving it a try and getting used to the "java way" of this.
source to share