is it possible to pass primitive data to a method as argument in java, without wrapping them into corresponding class objects ???
-
1Just to be a bit pedantic as I completely understand what you're asking, nothing is passed by reference in Java, everything is pass by value. – Chris Thompson Jan 05 '11 at 05:16
-
Also, see this http://stackoverflow.com/questions/2113656/how-to-overcome-the-fact-that-primitives-are-passed-by-value – Chris Thompson Jan 05 '11 at 05:18
4 Answers
Don't do this, but since you asked....you can put them in 1 element lengthed arrays, and pass the array.

- 28,272
- 7
- 61
- 66
-
3that won't modify the actual data only the array... can we do it more abstractly ?? – Mahesh Gupta Jan 05 '11 at 05:19
-
one if the none-practical answers I've ever seen. This's why everyone should try to read and study from books!!! – Ehsan Feb 25 '16 at 21:52
In Java, it is not possible to pass primitives by reference. To emulate this, you must pass a reference to an instance of a mutable wrapper class.
See How do I pass a primitive data type by reference? for more info on mutable wrapper classes.

- 1
- 1

- 10,027
- 3
- 40
- 54
Short Answer: No Way!!
Long Answer: Primitive data are pass by value not by reference, why? Because they are not object.
"Primitive values do not share state with other primitive values." Oracle Official Tutorial
Nevertheless if you still are intending to do this you may wanna take a look into Wrapper classes, each primitive has its homologue as a Wrapper
If you have a question when to use primitive or wrapper take a look to "When to use primitive and when reference types in Java"