Tag: 不可达代码

为什么Java仅在while循环的情况下识别无法访问的代码?

如果我有类似的代码 public static void main(String args[]){ int x = 0; while (false) { x=3; } //will not compile } 编译器会抱怨x=3是无法访问的代码但是如果我有代码那么 public static void main(String args[]){ int x = 0; if (false) { x=3; } for( int i = 0; i< 0; i++) x = 3; } 然后它正确编译,虽然if statement和for loop的代码是不可达的。 为什么java工作流逻辑没有检测到这种冗余? 任何用例?

为什么此代码会出现“无法访问的语句”错误?

这是我的代码,我得到一个无法访问的语句错误,但我不知道为什么。 public boolean Boardload(String[] args) throws Exception { Robot robot = new Robot(); Color color3 = new Color(114, 46, 33); Color color4 = new Color(180, 0, 0); { Rectangle rectangle = new Rectangle(0, 0, 1365, 770); { while(false) { BufferedImage image = robot.createScreenCapture(rectangle); search: for(int x = 0; x < rectangle.getWidth(); x++) { for(int y […]