除了其他答案,源代码:
字符.java
public static char toUpperCase(char ch) {
return (char)toUpperCase((int)ch);
}
public static int toUpperCase(int codePoint) {
return CharacterData.of(codePoint).toUpperCase(codePoint);
}
字符数据.java
static final CharacterData of(int ch) {
if (ch >>> 8 == 0) { // fast-path
return CharacterDataLatin1.instance;
} else {
switch(ch >>> 16) { //plane 00-16
case(0):
return CharacterData00.instance;
case(1):
return CharacterData01.instance;
case(2):
return CharacterData02.instance;
case(14):
return CharacterData0E.instance;
case(15): // Private Use
case(16): // Private Use
return CharacterDataPrivateUse.instance;
default:
return CharacterDataUndefined.instance;
}
}
}
CharacterData00.java(例如)
int toUpperCase(int ch) {
int mapChar = ch;
int val = getProperties(ch);
if ((val & 0x00010000) != 0) {
if ((val & 0x07FC0000) == 0x07FC0000) {
switch(ch) {
// map chars with overflow offsets
case 0x00B5 : mapChar = 0x039C; break;
case 0x017F : mapChar = 0x0053; break;
case 0x1FBE : mapChar = 0x0399; break;
// map char that have both a 1:1 and 1:M map
case 0x1F80 : mapChar = 0x1F88; break;
case 0x1F81 : mapChar = 0x1F89; break;
case 0x1F82 : mapChar = 0x1F8A; break;
case 0x1F83 : mapChar = 0x1F8B; break;
case 0x1F84 : mapChar = 0x1F8C; break;
case 0x1F85 : mapChar = 0x1F8D; break;
case 0x1F86 : mapChar = 0x1F8E; break;
// Many more
}
}
else {
int offset = val << 5 >> (5+18);
mapChar = ch - offset;
}
}
return mapChar;
}
如您所见:绝不会发生装箱/拆箱。