簡體   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