java标识符例子_unicode - Java标识符中的“连接字符”是什么?

连接字符用于连接两个字符。

在Java中,连接字符是Character.getType(int codePoint)/Character.getType(char ch)返回的值等于Character.CONNECTOR_PUNCTUATION的字符。

请注意,在Java中,字符信息基于Unicode标准,该标准通过为连接字符分配通用类别Pc来标识连接字符,该类别是Connector_Punctuation的别名。

以下代码段,

for (int i = Character.MIN_CODE_POINT; i <= Character.MAX_CODE_POINT; i++) {

if (Character.getType(i) == Character.CONNECTOR_PUNCTUATION

&& Character.isJavaIdentifierStart(i)) {

System.out.println("character: " + String.valueOf(Character.toChars(i))

+ ", codepoint: " + i + ", hexcode: " + Integer.toHexString(i));

}

}

打印可用于在jdk1.6.0_45上启动标识符的连接字符

character: _, codepoint: 95, hexcode: 5f

character: ‿, codepoint: 8255, hexcode: 203f

character: ⁀, codepoint: 8256, hexcode: 2040

character: ⁔, codepoint: 8276, hexcode: 2054

character: ・, codepoint: 12539, hexcode: 30fb

character: ︳, codepoint: 65075, hexcode: fe33

character: ︴, codepoint: 65076, hexcode: fe34

character: ﹍, codepoint: 65101, hexcode: fe4d

character: ﹎, codepoint: 65102, hexcode: fe4e

character: ﹏, codepoint: 65103, hexcode: fe4f

character: _, codepoint: 65343, hexcode: ff3f

character: ・, codepoint: 65381, hexcode: ff65

以下编译在jdk1.6.0_45上,

int _, ‿, ⁀, ⁔, ・, ︳, ︴, ﹍, ﹎, ﹏, _, ・ = 0;

显然,上述声明无法在jdk1.7.0_80&amp; jdk1.8.0_51用于以下两个连接字符(向后兼容... oops !!!),

character: ・, codepoint: 12539, hexcode: 30fb

character: ・, codepoint: 65381, hexcode: ff65

无论如何,除了细节,考试只关注Basic Latin字符集。

此外,对于Java中的合法标识符,此处提供了规范。 使用Character类API获取更多详细信息。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值