Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recompile with -Xlint:deprecation for details

Tags:

java

I need to know how to fix these error notes:

Note: Summer.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Here is my code:

import java.util.Calendar;
import java.util.*;

class Summer
{
    public static void main(String[] args)
    {
        Date d1 = new Date();
        Date j21 = new Date(d1.getYear(), 6, 21);
        if(d1.before(j21)) {
            long diff = j21.getTime() - d1.getTime();
            diff = diff / (1000 * 60 * 60 * 24);
            System.out.println("There are " + diff + " days until June 21st" );
        }
        else {
            long diff = d1.getTime() - j21.getTime();
            diff = diff / (1000 * 60 * 60 * 24);
            diff = 365 - diff;
            System.out.println("There are " + diff + " days until June 21st" );
        }
    }
}
like image 704
Dave Walters Avatar asked Sep 24 '12 02:09

Dave Walters


People also ask

What does recompile with Xlint mean?

By "recompile with -Xlint", the compiler means to inform you that you need to recompile your program like this: javac -Xlint abc.java. If you do so, the compiler will tell you which methods are deprecated so you can remove your calls to them.

How do I fix Java unchecked or unsafe operations?

You can resolve this warning message by using generics with Collections. In our example, we should use ArrayList<String> rather than ArrayList() . When you will compile above code, you won't get warning message anymore. That's all about how to fix uses unchecked or unsafe operations.


2 Answers

This is not an error; it's a warning message.

Your program would run as you wrote it.

The reason why the compiler is giving you this warning is because you have used a deprecated function call.

By "recompile with -Xlint", the compiler means to inform you that you need to recompile your program like this:

javac -Xlint abc.java 

If you do so, the compiler will tell you which methods are deprecated so you can remove your calls to them. (If some method is deprecated, it usually means that a better implementation is available and that you should use that instead of the deprecated method.)

like image 167
Mukul Goel Avatar answered Sep 28 '22 04:09

Mukul Goel


It's a warning. You're using a deprecated function call or object. You can recompile like so to find out where it's occurring:

javac -Xlint:deprecation Summer.java

Generally, it's a bad idea to use deprecated libraries. They may go away in the next release.

like image 25
Makoto Avatar answered Sep 28 '22 05:09

Makoto