Java Show Strike Line on Methods

为什么它在getDate(),getMonth()和getYear()上显示警示线.这些方法用于获取当前日期,月份和年份,但我不知道为什么它显示这些方法的攻击.

码:

public class hello {

    public static void main(String[] args) {
        int days;
        int month;
        int year;

        days = 24;
        month = 10;
        year = 1994;

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

        Date d = new Date();

        int t = d.getDate();
        int x = d.getMonth() + 1;
        int f = d.getYear() + 1900;

        System.out.println("Current Date: " + t + "/" + x + "/" + f);
    }
}

解决方法:

像Eclipse这样的IDE如果被弃用就会攻击这些方法,这意味着它们不推荐使用,因为有更好的选择.见Javadocs of getDate()

Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_MONTH).

使用日历方法:

Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH) + 1;
int year = calendar.get(Calendar.YEAR);
上一篇:java – Torch / Flashlight应用程序(不推荐使用android.hardware.camera)


下一篇:python – OpenGL新手和弃用