Xlint:弃用警告

时间:2014-11-07 12:58:11

标签: windows-7 java cmd

import java.text.ParseException; 
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Age
{
   public static void main(String []args)
     {
    Scanner input = new Scanner( System.in );

    int daysInMon[] = {31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31};  //Days in month
        int days, month, year;
        char[] dob = new char[110];

    System.out.println("Please Enter your Day of Birth(1-31): ");
        days = input.nextInt();

    System.out.println("Please Enter your Month of Birth(1-12): ");
        month = input.nextInt();

    System.out.println("Please Enter your Year of Birth(1900): ");
        year = input.nextInt();

        System.out.println("Your Date of Birth: "+days+ "/" +month+ "/" +year);

    Date d = new Date();

        System.out.println("Current Date: " +d.getDate()+ "/" +(d.getMonth()+1)+ "/" +(d.getYear()+1900));

        days = daysInMon[month - 1] - days + 1;

        days = days + d.getDate();
        month = (12 - month) + d.getMonth();
        year = (d.getYear() + 1900) - year - 1;

        if (month >= 12)
        {
        year = year + 1;
        month = month - 12;
        }


        System.out.println("Age:" +year+ "years" +month+ "months" +days+ "days");
     }
}

这是我根据键盘输入生成Age的代码。当我通过cmd编译时,我显示了两个音符。然后我使用-Xlint重新编译它显示:

Xlint:deprecation Warning

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

正在使用这些已弃用的方法,这会引出弃用警告:

d.getDate()
d.getMonth()
d.getYear()

如果您想避免弃用警告,请改用这些方法。

Calendar.get(Calendar.DAY_OF_MONTH)
Calendar.get(Calendar.MONTH)
Calendar.get(Calendar.YEAR)

有关详细信息,请参阅Date class