Java 此字符串中的哪些字符会抛出错误无效字符常量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24263049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What characters in this string throw the error invalid character constant?
提问by jsmos
I'm following an example online, and in one of the lines of code it has this string:
我正在关注一个在线示例,在其中一行代码中,它包含以下字符串:
Pattern screenNamePattern = Pattern.compile('(@[a-zA-Z0-9_]+)');
When I put it into Eclipse, it throws the error "invalid character constant." What strings in here throw that error? I'm confused...
当我将它放入 Eclipse 时,它会抛出错误“字符常量无效”。这里的哪些字符串会抛出该错误?我糊涂了...
采纳答案by laalto
Put it in "double quotes"
instead of 'single quotes'
.
把它放在"double quotes"
而不是'single quotes'
.
Double quotes are for string literals, single quotes are for single character constants.
双引号用于字符串文字,单引号用于单个字符常量。