简体   繁体   English

java 变量未初始化

[英]java variables not being initialized

I have the following code which outputs 0 and 5 when run the first time.我有以下代码在第一次运行时输出 0 和 5。 However, if I rerun the program I get 5 and 5 from BlueJ (ide) and 0 and 5 from coding roooms (ide).但是,如果我重新运行程序,我会从 BlueJ (ide) 获得 5 和 5,从编码 roooms (ide) 获得 0 和 5。 Is this a bug in BlueJ?这是 BlueJ 中的错误吗?

UPDATE: spoke to the BlueJ support team.更新:与 BlueJ 支持团队交谈。 BlueJ has an extension called "Run Main Method" that is causing the problem. BlueJ 有一个名为“Run Main Method”的扩展,它导致了这个问题。 If you use void main(String[] args) the program runs as intended如果您使用 void main(String[] args) 程序按预期运行

here's the code:这是代码:

public class Bug
{
    private static int x = 0;
    
    public static void main(String[] args){
        System.out.println("\f");
        
        System.out.println(x);
        x=5;
        System.out.println(x);
    }
}

Yes, this is probably a bug in BlueJ as both in Eclipse and IntelliJ the output is是的,这可能是 BlueJ 中的一个错误,因为 Eclipse 和 IntelliJ 中的 output 都是

0
5

In any case the above should be the correct output in any IDE as per the rules of the Java language在任何情况下,根据 Java 语言的规则,以上内容应该是任何 IDE 中正确的 output

Yes, That is a problem with BlueJ.是的,这是 BlueJ 的问题。


You don't have to put the String[] args in BlueJ.您不必将 String[] 参数放在 BlueJ 中。 It still works.它仍然有效。

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

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