Java记录 -28- String Literals字面值
来源:互联网 发布:网络抓包软件 编辑:程序博客网 时间:2024/05/21 11:11
String Literals (Java语言规范Java Language Specifications)
The program consisting of the compilation unit :
package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " ");
System.out.print((hello == ("Hel"+lo)) + " ");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }
and the compilation unit:
package other;
public class Other { public static String hello = "Hello"; }
produces the output:
true true true true false true
This example illustrates six points:
1). Literal strings within the same class in the same package represent references to the same String object .
2). Literal strings within different classes in the same package represent references to the same String object.
3). Literal strings within different classes in different packages likewise represent references to the same String object.
4). Strings computed by constant expressions are computed at compile time and then treated as if they were literals.
5). Strings computed by concatenation at run time are newly created and therefore distinct.
6). The result of explicitly interning a computed string is the same string as any pre-existing literal string with the same contents.
- Java记录 -28- String Literals字面值
- String Literals
- Objective-C字面量(Objective-C Literals)
- objective-c 2.0的字面量Literals
- Playgrounds中的字面量(Literals)
- #Objective - C - 字面量(Literals)整理
- Objective - C - 字面量(Literals)整理
- 9.4.4.5 String literals
- Printing with String Literals
- Java记录 -26- StringPool和字面赋值
- Java Floating-Point Literals
- Java 7 二进制字面值
- 1105 Java中String字面值对象和构造方法创建对象的区别
- java面试题:String字面值对象和构造方法创建对象的区别
- 关于字面量的理解(Objective-C Literals)
- ES6之对象字面量扩展语法(Enhanced Object Literals)
- 字面量(literal)与 C 语言复合字面量(compound literals)
- java字符串字面量是否生成String对象
- 在线工具
- Java记录 -24- equals方法重写
- Java记录 -25- String类深度剖析
- Java记录 -26- StringPool和字面赋值
- Java记录 -27- String的intern方法
- Java记录 -28- String Literals字面值
- Java记录 -29- StringBuffer
- Java记录 -30- 包装类
- Leetcode 383 Ransom Note
- Java记录 -31- Java数组
- Java记录 -32- 值交换
- Java IO读写大文件的几种方式及测试
- Hadoop之父Doug Cutting
- TPS和QPS