Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent IntelliJ from deleting import statements

I am taking the University of Stanford algorithms course (via Coursera). This course uses IntelliJ as the programming environment as well as well as some libraries built for the course. In particular, it uses some StdOut and StdIn libraries to deal with standard output and input.

If I just write my code and try to compile it via the terminal, it will throw the eror

error: cannot find symbol; symbol: variable StdOut.

I figured out that the problem can be solved by adding import statements:

import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

However, IntelliJ deletes these statements as soon as I add them. But, if I compile again, it compiles without errors, so it looks like IntelliJ is importing these libraries and then deleting the statements.

The problem is, if I close and reopen the project, and compile again, it gives me again the missing symbol error, which forces me to re-write the import statements.

My question is, I don't like the idea of re-writting these statements every time I close and open the project, I just want to IntelliJ to stop messing with my code and leave the statements in there. Since I'm just a beginner, I want to focus on learning about the algorithms, not on fighting against IntelliJ features, so I'm OK with completely disabling any kind of auto import and I will just handle all the imports manually.

I went to settings/Editor/General/Autoimport and basically disable everything, and yet IntelliJ still deletes my import statements.

Thanks you for your help!

like image 941
Miguel GC Avatar asked Oct 22 '25 01:10

Miguel GC


1 Answers

It isn't actually deleting your import-statements, just folding them. With other words, it just doesn't show the lines in which the import-statements are, mainly for readability. You can disable this behaviour in the following manner: Disable the following:

Settings -> Editor -> General -> Code Folding -> Imports

However, if intelliJ really deletes the lines, disable the following:

Settings -> Editor -> General -> Auto Import -> Optimize imports on the fly
like image 145
CWuest Avatar answered Oct 24 '25 14:10

CWuest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!