in C++, I can do it by:
void getParam(int *width, int *height);
int width, height;
getParam(width, height);
but how can I do it in JAVA because JAVA does not accept point?
Printable View
in C++, I can do it by:
void getParam(int *width, int *height);
int width, height;
getParam(width, height);
but how can I do it in JAVA because JAVA does not accept point?
hi there,
Could you explain more specific what you want (and not how to do it in C++) ?
Greets,
Jan Meeuwesen.
Well,
In Java, all objects are passed by reference.
So any modifications that you make to the passed
arguments will be reflected back as in C++.
Thanks.
Returning multiple values via a return statement is not allowed in Java. Thankfully.
If you truly wish to get back multiple values, consider creating a new object to hold your values. Often times, at least in business apps, you'll end up adding behavior and/or additional attributes anyway.
If this doesn't seem appropriate in your case, then maybe rethink your design a bit, such that you don't need multiple return values. The entire Java language is written without multiple return values...
good luck,
You can either break it up into two methods
int getWidth();
int getHeight();
or return an object with all the information
java.awt.Dimension getSize();
Actually if you pass 2 object parameters into the method such as : myMethod(Object a, Object b), then the objects can be modified, since it a reference your passing.
So in terms of you argument, it would look a little more like:
public void getParam(Integer width, Integer height) {
width = new Integer(100);
height = new Integer(100);
}
However this may be more effort than its worth (when you want plain int values).
If you have to send them back at the same time, you could also return a Dimension Object.
Dustin