繁体   English   中英

未使用局部变量的值

[英]The value of the local variable is not used

上面的所有变量在标题中都有警告。 你能告诉我为什么会这样吗?

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

您声明的变量从未使用过,只分配给过,因此您会被警告。

您已经定义了变量: xyssnphonenumtwoLine 但是您永远不会在代码中的任何地方使用这些变量。 例如,如果您将变量打印出来:

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

所有警告都应该消失

暂无
暂无

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

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