The value of the local variable is not used

倖福魔咒の 提交于 2021-02-05 12:34:33

问题


all of the variables above have the warning in the title. Could you please tell me why that is happening?

public class DataTypes {
    public static void main(String[] argv) {
        // new feature in JDK 7
        int x = 0b1010; // 12
        int y = 0b1010_1010;
        int ssn = 444_12_7691;
        long phone = 408_777_6666L;
        double num = 9_632_401_909.1_0_3;
        String twoLine = "line one\nline two";
    }
}

回答1:


The variables you declared are never used, only assigned to, therefore you're being warned.




回答2:


You have defined the variables: x, y, ssn, phone, num and twoLine. But you never use the variables anywhere in the code. For instance, if you print the variables out:

System.out.println(x + y + ssn + phone + num + twoLine);

All the warnings should disappear



来源:https://stackoverflow.com/questions/36728961/the-value-of-the-local-variable-is-not-used

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!