Reputation:
I have encountered a problem where my code compiles and runs fine in NetBeans, but when I try to compile with the command line using javac, I get an unchecked warning error and it fails. When I compile with -Xlint:unchecked, I get a detailed description of the error that points to where the issue is.
Here I fail to properly use generics and is where my problem is:
List<String> name = new ArrayList();
After adding the diamond operator the code now compiles fine in and out of the IDE
List<String> name = new ArrayList<>();
It seems that in the first example I must use casting, whereas the second uses generics.
My question is: Is this a bug in the IDE? NetBeans seems to catch all sorts of other errors, but why would my code compile fine in the IDE but not with the command line? It should be obvious that I am new to programming, so please forgive me if I have failed to offer a question of any significance.
Information that comes close to answering my question: The Java™ Tutorials, What is the point of the diamond operator in Java 7?(stackOverflow)
I have looked up and found Bug 250587, but not the same. Also, I am up-to-date with no updates available on NetBeans. My javac version is 1.8.0_91
Thanks for taking the time to read this.
Upvotes: 1
Views: 615
Reputation: 81578
Not a bug,
List<String> name = new ArrayList(); //this instantiates a raw type of `ArrayList`
And
List<String> name = new ArrayList<String>(); // this instantiates an `ArrayList` with parametric type `String`
And
List<String> name = new ArrayList<>(); // this is a short-hand since Java 7 for the above
Upvotes: 1