0 votes
1 view
in Java by (3.5k points)

For example:

javac Foo.java

Note: Foo.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

1 Answer

0 votes
by (46.1k points)

This develops up in Java 5 and later if you're doing collections without type specifiers (e.g., Arraylist() rather of ArrayList<String>()). It implies that the compiler can't check that you're using the collection in a type-safe way, using generics.

To get rid of the signal, just be particular about what type of objects you're storing in the collection. So, rather of

List myList = new ArrayList();

use

List<String> myList = new ArrayList<String>();

In Java 7 you can reduce generic instantiation by applying Type Inference.

List<String> myList = new ArrayList<>();

Related questions

+13 votes
2 answers
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...