Not all Java IDEs give the same compiler warnings
One might assume that all integrated development environments (IDEs) for Java programming all give the same warnings. One would be wrong to assume that.
The main thing that is consistent across the three major Java IDEs (Eclipse, Apache NetBeans and JetBrains IntelliJ IDEA) is that they indicate warnings with the color yellow. A lot of other things differ.
I will write another article later on in which I try to give a comprehensive list of warnings unique to each of the three major Java IDEs. In this article, I will only give one example of a difference for each of the three major Java IDEs.
For the rest of this article, I assume that you have not reconfigured your IDE in any way, or at least not pertaining to warnings or “code inspections,” that you’re using it “out of the box,” so to speak.
Eclipse
If you mark a class as Serializable
, or you start off a subclass of a class implementing that interface in Eclipse, even if your new class is abstract, the IDE will warn you that you have not defined serialVersionUID
. For example:
package org.example;
public class ExampleException extends RuntimeException {
}
Eclipse will give you three distinct indications of one warning.
But as soon as you add something like
private static final long serialVersionUID = 4294967296L;
the warning disappears: no yellow square on the upper right corner of the editor, no yellow underline for the class name, and no yellow indicator to the left of the line number for the class declaration.
NetBeans
If you had tried the preceding example in Apache NetBeans, you would have seen a green indicator in the upper right corner of the editor window the whole time: from the moment you started the class, and when you added the serialVersionUID
.
Nor will NetBeans warn you about unchecked casts, such as you might need to do when creating data structures with generics. Examples: ArrayList<E>
and LRUCache<N, V>
. The way I implemented the latter, these two lines cause warnings in Eclipse and IntelliJ but not NetBeans.
this.names = (N[]) new Object[this.capacity];
this.values = (V[]) new Object[this.capacity];
There are only two ways to quiet these warnings in Eclipse or IntelliJ: either add the annotation @SuppressWarnings
with the Unchecked attribute (might be acceptable), add that annotation with the All attribute (almost certainly a bad idea) or reconfigure the IDE.
IntelliJ IDEA
If you bring in my LRUCache<N, V>
into an IntelliJ project, the IDE will give you six warnings. If you also bring in the test class, IntelliJ will reduce the number of warnings in the class under test to just two, the same ones as in Eclipse.
Anything that’s not used in your project causes a warning. It can be a little annoying when you’re starting a project and you’re trying to figure out what classes and interfaces you will need.
But you will appreciate it when, after a few rounds of refactoring later on in your work on the project, fields and functions you thought you would need, even whole classes, turn out to not be necessary. Then the warnings will point out things you can safely delete.
As for the ExampleException
example, IntelliJ will also give you one warning. But not because of the serialVersionUID
, but because you don’t have any usages of it in your project yet. It doesn’t matter to IntelliJ what the access level is.