最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Java中的字符串常量const的String出错:Syntax error on token "const", delete this token

Java crifan 3490浏览 0评论

【背景】

折腾:

【教程】模拟登陆百度之Java代码版

期间,需要写几个全局的,const的String。

【折腾过程】

1.结果是参考自己的:

【已解决】Android(Java)中的const变量定义出错:Syntax error on token "const", delete this token

把:

会报错:

Syntax error on token "const", delete this token

Syntax error on token const delete this token

private const String gUserAgent = "";

去改为:

private static final String gUserAgent = "";

就可以了:

static finnal string is ok

 

【总结】

想要实现常量字符串,使用:

static final String strValue = "your string";

即可。

转载请注明:在路上 » 【已解决】Java中的字符串常量const的String出错:Syntax error on token "const", delete this token

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.176 seconds, using 22.09MB memory