Reputation: 307
I was wondering what are the main reasons why eclipse warns developers about the following things:
I'm thinking that one reason is to make code cleaner. Anyone knows a list of reasons behind those warnings (like memory concerns, and things like that)?
Thanks!
Upvotes: 1
Views: 172
Reputation: 1223
It's mostly to make the code readable and avoid clutter - it's easy to loose track when a file starts getting large, and having non-functional lines of code are therefor best to avoid. It's mostly for readability... Well, and by removing unused imports, you ease the compilers job ever so slightly (read: very slightly).
If Eclipse notice an unused import or variable, you can be damn sure that the compiler does so as well (since eclipse is actually compiling the code while you code to generate those warnings). The compiler will try to optimize it as much as possible, so if it sees an unused variable (or import), it doesn't bother to include them in the compiled byte code.
But it's generally good coding style not to have unused code;
In Java and (most) other high-level languages, you generally don't have to worry about those things, since you don't have to manage memory-allocation. But supposing the compiler didn't catch it for whatever reason when compiling (perhaps if you were writing in another programming language), the object or data referenced by a variable would then be taking up memory space, and if you a lot of those unused variables that all took up memory space... that could potentially be a lot of memory used for nothing.
Upvotes: 1
Reputation: 121998
you are unnecessarily declared/imported
the variable/import.
Removing them keeps the code cleaner and easier to read.By default Eclipse warns you about unused private variables and methods.
But do not change these warning preferences,It's helpful to identify your unused code.
Upvotes: 0
Reputation: 93842
This prevents you that you writed Unnecessary code
. According to the help of Eclipse (Java Compiler Errors/Warnings Preferences) this says :
"When enabled, the compiler will issue an error or a warning whenever a local variable is declared but its value never used within its scope."
Upvotes: 1
Reputation: 2785
The value of the local variable xxx is not used
It is declared when you only declare or assign a value to a variable, but you never used it for anything. It is warning you because it does nothing in your code, so it would be better to remove it.
The import XXX is never used
The same thing as the other one. There is no need to import a classe you won't use, so Eclipse recommends you to remove the import, since it does nothing but pollute the code.
Upvotes: 1
Reputation: 4103
Yes why should you include code, that is never used?
I guess the compiler will remove this unused code anyway, but you should keep the code as clean as possible by yourself.
Upvotes: 1