Click to See Complete Forum and Search --> : Passing primitive types by reference


Brad Cadle
February 7th, 1999, 04:35 PM
Hi All,

I am a java beginner. I quickly went through The Microsoft Visual j++ source book. Fortunately, it is recommended by Java-SIG so the information covers only those aspects of j++ that are true java. In addition, I have been going through the much more complete book (transfered from this site), "Thinking in Java". I have a background in C, C++, Fortran. This question will probably seem basic but I have not yet seen it discussed in either book.


How does one pass a primitive type by reference? The closest thing to doing so that i can see to to create a 1 element array of that type and pass the array. Alternatively one could use the object wrappers for the primitive types, but it seems like there would be a lot of overhead in creating the object, making it inefficient.

-Brad

brad Cadle
February 7th, 1999, 04:35 PM
Hi All,

I am a java beginner. I quickly went through The Microsoft Visual j++ source book. Fortunately, it is recommended by Java-SIG so the information covers only those aspects of j++ that are true java. In addition, I have been going through the much more complete book (transfered from this site), "Thinking in Java". I have a background in C, C++, Fortran. This question will probably seem basic but I have not yet seen it discussed in either book.


How does one pass a primitive type by reference? The closest thing to doing so that i can see to to create a 1 element array of that type and pass the array. Alternatively one could use the object wrappers for the primitive types, but it seems like there would be a lot of overhead in creating the object, making it inefficient.

-Brad

Zafir Anjum
February 7th, 1999, 05:52 PM
Use the second approach. That is, use the wrapper classes. It has no more overhead

than using a 1 element array since an array too is a Java object. Using the

wrapper classes is the reccomended way.

Brad Cadle
February 7th, 1999, 06:55 PM
Thanks Zafir,

Your help with my posting has been useful thus far. Are you the moderated of this discusion board?


-Brad

brad Cadle
February 7th, 1999, 06:55 PM
Thanks Zafir,

Your help with my posting has been useful thus far. Are you the moderated of this discusion board?


-Brad