We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
P114页,8.12.1(常量池中已存在字符串) 以下代码的执行结果: 书上:false,true idea(JDK8,JDK21):false,false ` @test public void internTest(){ String s1 = new String("1"); s1.intern(); String s2 = "1"; System.out.println("s1 == s2 : " + (s1 == s2));
System.out.println("========================="); String s3 = "1" + "1"; s3.intern(); String s4 = "11"; System.out.println("s3 == s4 : " + (s3 == s4)); }
`
修正代码: s3.intern()——>s3 = s3.intern(); ` @test public void internTest(){ String s1 = new String("1"); s1.intern(); String s2 = "1"; System.out.println("s1 == s2 : " + (s1 == s2));
System.out.println("========================="); String s3 = "1" + "1"; s3 = s3.intern(); String s4 = "11"; System.out.println("s3 == s4 : " + (s3 == s4)); }
` 此时打印结果为:true false
The text was updated successfully, but these errors were encountered:
No branches or pull requests
P114页,8.12.1(常量池中已存在字符串)
以下代码的执行结果:
书上:false,true
idea(JDK8,JDK21):false,false
`
@test
public void internTest(){
String s1 = new String("1");
s1.intern();
String s2 = "1";
System.out.println("s1 == s2 : " + (s1 == s2));
`
修正代码:
s3.intern()——>s3 = s3.intern();
`
@test
public void internTest(){
String s1 = new String("1");
s1.intern();
String s2 = "1";
System.out.println("s1 == s2 : " + (s1 == s2));
`
此时打印结果为:true false
The text was updated successfully, but these errors were encountered: