For example:
javac Foo.java
Note: Foo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
For example:
javac Foo.java
Note: Foo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
The solution would be to use specific type in
<>
likeArrayList<File>
.example:
above code generate warning because
ArrayList
is not of specific type.above code will do fine. Only change is in third line after
ArrayList
.If you do what it suggests and recompile with the "-Xlint:unchecked" switch, it will give you more detailed information.
As well as the use of raw types (as described by the other answers), an unchecked cast can also cause the warning.
Once you've compiled with -Xlint, you should be able to rework your code to avoid the warning. This is not always possible, particularly if you are integrating with legacy code that cannot be changed. In this situation, you may decide to suppress the warning in places where you know that the code is correct:
This warning means that your code operates on a raw type, recompile the example with the
to get the details
like this:
docs.oracle.com talks about it here: http://docs.oracle.com/javase/tutorial/java/generics/rawTypes.html
for example when you call a function that returns Generic Collections and you don't specify the generic parameters yourself.
for a function
will generate this error.
To solve it you would just add the parameters
I just want to add one example of the kind of unchecked warning I see quite often. If you use classes that implement an interface like Serializable, often you will call methods that return objects of the interface, and not the actual class. If the class being returned must be cast to a type based on generics, you can get this warning.
Here is a brief (and somewhat silly) example to demonstrate:
getInstance() returns an object that implements Serializable. This must be cast to the actual type, but this is an unchecked cast.
For Android Studio, you need to add:
in your project's build.gradle file to know where this error is produced.