简体   繁体   中英

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

Is there anything like 'is' in Java? Something that would evaluate to true based on memory location?

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

Suppose you have three strings:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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