如何在java中输入String content:encoded = "Hello";
?
Eclipse 一直告诉我 token 语法错误删除这些 token ?
setDescription(String content:encoded) {
_description = content:encoded;
}
最佳答案
因为content:encoded
是语法错误。 Java 中的名称只接受字母数字$
和“_”。该规则可能允许其他一些字符,但应该差不多。变量也不能以数字开头。
为了清楚起见,请从变量名中删除 :
,因为 :
在名称中是非法的,并且在语言中可能具有其他含义。
引自以下文章:
- Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign
$
, or the underscore character_
. The convention, however, is to always begin your variable names with a letter, not$
or_
. Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with_
, this practice is discouraged. White space is not permitted.- Subsequent characters may be letters, digits, dollar signs, or underscore characters.
在这里阅读更多相关信息:http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html
关于java - 如何键入字符串内容 :encoded = "Hello"; in java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21529392/