错误:不声明在Java中的布尔值时,声明 [英] Error: not a statement when declaring a boolean in Java

查看:159
本文介绍了错误:不声明在Java中的布尔值时,声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code:

boolean continue = false;

返回以下错误:

error: not a statement
  boolean continue = false;
  ^

这是怎么回事?我是pretty熟悉布尔值。

Why is this happening? I am pretty familiar with booleans.

推荐答案

试试这个:

boolean cont = false;

或使用其他名称。问题的关键是,在Java中,继续是的关键字,它不能被用来作为一个变量名 - 这是正确的此处中的语言规范。对于未来的参考这就是继续用于:

Or use another name. The point is that in Java, continue is a keyword and it can't be used as a variable name - it's right here in the language specification. For future reference this is what continue is used for:

继续语句跳过,而做的,而循环。未标记的形式跳过最内层循环体的结束和评估布尔前pression将控制循环。

The continue statement skips the current iteration of a for, while, or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop.

这篇关于错误:不声明在Java中的布尔值时,声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆