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" );
}
}
}
解决方案
This is not an error , its 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 , compiler means to inform you that you need to recompile your program as
javac -Xlint abc.java
if you do so, the compiler will tell which methods are deprecated so you could remove those.
"basically if some method is deprecated, a better implementation is provided" so the complier pops up a warning informing that something better has been provided for what you are trying to use"
PS: it is always advisable not to use deprecated methods.
Hope it helps :-)