开发者

Recompile with -Xlint:unchecked for details

while compiling java program we are getting "Recompile with -Xlint:un开发者_运维百科checked for details". Why we are getting this error?


Probably because you're not using generics properly. Perhaps you're mixing legacy code with generic code.

Here's a quote fro the official trail on type erasure:

Note: WarningDemo.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

This can happen when using an older API that operates on raw types, as shown in the following WarningDemo program:

public class WarningDemo {
    public static void main(String[] args) {
        Box<Integer> bi;
        bi = createBox();
    }

    static Box createBox() {
        return new Box();
    }
}

I suggest you follow the advice, and add the -Xlint:unchecked option when compiling. This should reveal the which parts of the code that are problematic.


This option enables/disables specific warnings. It seems that your code produces these warnings. If you are using IDE as well pay attention on the warning it produces too. It may be very helpful.

And try to do what compiler offers you: just recompile with this option and see what will happen.


Probably, that is because you need to declare a List object, say (e.g.), without omitting '<' and '>':

List<Integer> list = new ArrayList<Integer>();

I tried to declare object in stack without in NetBeans, and NetBeans compiled my code with no error messages. Maybe, things are different with javac compiler.


Whenever you compile a Java file that includes a java.util.*; package, it must be recompiled with -xlint.

Also, Check your jdk version (using java -version). I am sure it must old. Install a new version of Java (like version 7) and you won't get the warning.


It could be caused by the jdk version mismatch, not necessarily the old jdk version but any version other than expected can cause this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜