如何解决Java中是否有关键字,类似于Python的“是”?
在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
解决方法
假设您有三个字符串:
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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。