哪些表情符号可以在 Java 中用作变量,在 Eclipse 中可见?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29696768/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:33:30  来源:igfitidea点击:

Which emoji can be used as variables in Java, visible in Eclipse?

javaeclipse

提问by Gnoupi

This question might be related to today's XKCD.

这个问题可能和今天的XKCD有关

I discovered today that emoji could be used in variable names.

我今天发现 emoji 可以用在变量名中。

int ?_? = 42; //apparently something valid

Out of curiosity, is there a list of such special characters which can be used in Java, and in a way which is readable by Eclipse?

出于好奇,是否有一个可以在 Java 中使用的特殊字符列表,并且可以通过 Eclipse 读取?

采纳答案by das Keks

Even if Javaallows to use characters from the entire Unicode set it seems like Eclipse only allows a few.

即使Java允许使用整个 Unicode 集中的字符,Eclipse 似乎也只允许使用少数字符。

Since I couldn't find a list of supported emojis I tried it out myself and found the following as working:

由于我找不到支持的表情符号列表,我自己尝试了一下,发现以下内容有效:

?????????????秘祝??????????????????↗↘↙↖?????????????????
???????????????????????????★☆??????????????????????????????
→???????????????????????????ツ??`

If you find more feel free to edit my answer and add them.

如果您发现更多,请随时编辑我的答案并添加它们。

EDIT:I think there are now a lot more supported emojis than back then. You can also use thousands of letters from the chinese alphabet.

编辑:我认为现在支持的表情符号比当时多得多。您还可以使用中文字母表中的数千个字母。

回答by M Anouti

You can find this information in the Java Language Specification section on identifers:

您可以在 Java Language Specification 中关于 identifers 的部分找到此信息:

An identifieris an unlimited-length sequence of Java lettersand Java digits, the first of which must be a Java letter.

...

Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.

一个标识符是无限长序列的Java字母爪哇位,其中第一个必须是一个爪哇字母

...

字母和数字可以从整个 Unicode 字符集中提取,它支持当今世界上使用的大多数书写脚本,包括中文、日文和韩文的大集。这允许程序员在用他们的母语编写的程序中使用标识符。

In this case, you're using the Unicode character \u0ca2.

在本例中,您使用的是 Unicode 字符\u0ca2

回答by theJollySin

Short Answer:Any emoji which is standard in the unicode character set will be a valid variable name in Java, Swift, or JavaScript.

简短回答:任何在 unicode 字符集中是标准的表情符号在 Java、Swift 或 JavaScript 中都是有效的变量名。

Long Answer:There are 1282 unicode emoji, which you can find here.

长答案:有 1282 个 unicode 表情符号,你可以在这里找到。

Emoji variable names are a joke.But not all emoji are happy/sad faces. Some emoji are animals, foods, buildings, clocks displaying various times, sports, various technologies, currencies, and flags. So it is entirely possible you could sometimes use an emoji as a useful descriptor of your variable.

表情符号变量名称是个笑话。但并非所有表情符号都是快乐/悲伤的面孔。一些表情符号是动物、食物、建筑物、显示不同时间的时钟、运动、各种技术、货币和旗帜。因此,有时您完全有可能使用表情符号作为变量的有用描述符。

Hereis a working Hello World example using emojis as variable names (they display correctly in my text editor, but not in GitHub's gist).

是一个使用表情符号作为变量名称的 Hello World 示例(它们在我的文本编辑器中正确显示,但不在 GitHub 的要点中)。

Please don't do this on any project I'm working on.

请不要在我正在从事的任何项目上这样做。