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

时间:2020-09-15 06:01:14

标签: java python keyword

在Java中是否有类似“是”的东西?根据内存位置可以评估为真的东西吗?

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

1 个答案:

答案 0 :(得分:0)

假设您有三个字符串:

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);