javaintellij-ideavarjava-10

Convert explicit type to var in IDEA


I have a Java 10 project with the following code:

Map<String, String> map = method();

When I put the cursor on Map... and press Alt+Enter, there should be an option "Replace explicit type with var". However, this option is missing from my menu.

How to enable this option? Should I clean some caches or something?

I'm using IDEA 2018.1.1 EAP.


Solution

  • The "Replace explicit type with 'var'" quick fix is provided by the Java | Java language level migration aids | Java 10 | Local variable type can be omitted inspection. Please check if you have this inspection enabled in your settings. It is not enabled automatically if you have the "Disable new inspections by default" setting enabled.