如何检查2个原始变量是否指向java中的相同值 [英] How to check whether 2 primitive variables point to same value in java

查看:71
本文介绍了如何检查2个原始变量是否指向java中的相同值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查2个原语是否指向Java中的相同值。例如对于Objects,我们可以像

How can I check if 2 "primitives" point to same value in Java.. For example for Objects, we can do it like

String a = "Xyz"; 
String b = "Abc";
boolean d = a == b; // == wont work for primitives!

基本上,我想检查一下用于在Java中通过引用传递如下..

Basically, I want to check for pass by reference in Java as follows ..

Integer b = sc.nextInt();
test(b); // Calling test method by passing int b;
static void test(int a){
// Check if a and b points to same value
}

What I have tried:

Checking for pass by reference in Java

推荐答案

此页面 Java是按值传递 [ ^ ]可能有助于您了解Java传递机制。
This page Java is Pass-by-Value[^] might help you to understand the Java passing mechanism.


这篇关于如何检查2个原始变量是否指向java中的相同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆