|
-
February 23rd, 2000, 05:20 PM
#1
how to return 2 value?
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?
-
February 24th, 2000, 03:25 AM
#2
Re: how to return 2 value?
hi there,
Could you explain more specific what you want (and not how to do it in C++) ?
Greets,
Jan Meeuwesen.
-
February 24th, 2000, 03:15 PM
#3
Re: how to return 2 value?
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.
-
March 7th, 2000, 02:40 PM
#4
Re: how to return 2 value?
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,
-
March 7th, 2000, 04:50 PM
#5
Re: how to return 2 value?
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();
-
March 7th, 2000, 08:30 PM
#6
Re: how to return 2 value?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|