简体   繁体   English

Xlint:弃用警告

[英]Xlint:deprecation Warning

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");
     }
}

This is my code to generate the Age according to the keyboard input. 这是我根据键盘输入生成年龄的代码。 When I compile through cmd I shows two notes. 通过cmd进行编译时,我会显示两个注释。 Then I recompile using -Xlint it shows: 然后我使用-Xlint重新编译,它显示:

Xlint:deprecation Warning

How can I fix this? 我怎样才能解决这个问题?

These deprecated methods are being used, which bring up the deprecation warning: 这些不赞成使用的方法正在使用,它会提出不赞成使用的警告:

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

If you want to avoid the deprecation warnings, use these methods instead. 如果要避免弃用警告,请改用这些方法。

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

See the Date class for more details. 有关更多详细信息,请参见Date类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM