Click here to Skip to main content
15,891,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I check if 2 "primitives" point to same value in Java.. For example for Objects, we can do it like
Java
String a = "Xyz"; 
String b = "Abc";
boolean d = a == b; // == wont work for primitives!
Basically, I want to check for pass by reference in Java as follows ..
Java
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
Posted
Updated 6-Mar-18 8:58am
Comments
Richard MacCutchan 6-Mar-18 15:17pm    
Primitives are values, not references,
Akshit Gupta 11-Mar-18 14:30pm    
Sir is there no way to check if they are pointing to same location?
Richard MacCutchan 12-Mar-18 4:13am    
No, because they are not pointers, they are values.

1 solution

This page Java is Pass-by-Value[^] might help you to understand the Java passing mechanism.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900