繁体   English   中英

Java 中是否有关键字,类似于 Python 的“is”?

[英]Is there a Keyword is in Java, similar to Python's "is"?

Java中有没有像'is'这样的东西? 根据内存位置评估为真的东西?

a = 1
b = a
print(id(a))
print(id(b))

# if a is b condition will evaluate to true
# the above print statement gives the same memory ID. In my case: 14374435888

# above assignment b = a is not the same as below
a = 1
b = 1

假设你有三个字符串:

String a = "first";
String b = "second";
String c = a;

// false, because they're in different memory locations
System.out.println(a == b);

// true, because they point to the same location in memory
System.out.println(a == c);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM