在JAVA变量名称中使用UTF-8字符 [英] using UTF-8 characters in JAVA variable-names

查看:298
本文介绍了在JAVA变量名称中使用UTF-8字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我可以使用我的母语字符(或字符串)作为 JAVA变量名称吗? 因此,我已经使用缅甸Unicode 进行了如下测试.

I would like to know that can I use my native language characters (or String) as JAVA variable names ? So, I had tested as below with Myanmar Unicode.

    public static void main(final String[] args) {
    String ဆဆဆ = "မောင်မောင်";
    System.out.println("ကောင်းသောနေ.ပါ " + ဆဆဆ);
}

此代码将我成功发送的消息显示为'ကောင်းသောနေ.ပါ'.但是在下面的代码中使用另一个变量名(也是我的母语String ).....

This code show my successful message as 'ကောင်းသောနေ.ပါ မောင်မောင်'. But in below code with another variable name (it also my native language String).....

    public static void main(final String[] args) {
    String တက်စတင်း = "မောင်မောင်";
    System.out.println("ကောင်းသောနေ.ပါ " + တက်စတင်း);
}

在我的 Ecliplse IDE 中产生编译时错误.

that produce compile time error in my Ecliplse IDE.

此行有多个标记 -令牌语法错误,请删除这些令牌 -出现异常-出现意外字符0x103a 标识符

Multiple markers at this line - Syntax error on tokens, delete these tokens - Got an exception - Unexpected character 0x103a in identifier

有什么建议吗?为什么会出现此问题?感谢您耐心阅读我的问题.

Any suggestion ? Why would this problem has occured ? Thanks for reading my question patiently.......

推荐答案

Java 6仅支持Unicode 4.0,这是Unicode的较旧版本,不包括缅甸(或至少仅包括基本语言).扩展的缅甸支持已添加到 Unicode 5.1 ,Java 7支持.

Java 6 merely supports Unicode 4.0, a quite old version of Unicode which doesn't include Myanmar (or at least only rudimentary). Extended Myanmar support was added to Unicode 5.1, which is supported in Java 7.

要解决此问题,请安装JDK 7(如果尚未安装),并配置Eclipse项目以将其编译为Java 7(Project-> Properties-> Java Compiler).请注意,编译为Java 7的代码不能在Java 6或更低版本上运行.

To resolve this issue, install JDK 7 if you haven't already, and configure your Eclipse project to compile as Java 7 (Project->Properties->Java Compiler). Please note that code compiled as Java 7 cannot be run on Java 6 or lower.

这篇关于在JAVA变量名称中使用UTF-8字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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