aspose file tools*
The moose likes Beginning Java and the fly likes instantiation again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "instantiation again" Watch "instantiation again" New topic
Author

instantiation again

Nazma Panjwani
Greenhorn

Joined: Jan 17, 2010
Posts: 17
Thank you guys........I was just curious as to how references worked....that's all..........I just used the Mammal class as an example.....
Some while back, I was working w/ arrays, and was trying to call a method that would change the size of an existing array...this method existed in a different class so I had to pass the array(whose size I wanted to change) as a parameter. Inside the method, I defined a temporary array (bigger array), copied all the values from the array that was passed, and then simply pointed the array (formal parameter) to the temp array. But ofcourse, the original array (actual parameter) did not point to the temp array (the bigger array). I figured out another way.....but then I became curious as to if there was a way in java which would allow this.....

By creating aliases, I can certainly change the state of an object, but I can't make one point to a new object (and have the other one automatically point to the new object as well).

Thanks for all your help.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
No problem .

Just an FYI, if you need to do that again (expand the size of your array) you can use something like an ArrayList, which increases its size as needed with no work on your part.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
well what you want to do is pretty much this ...



or if you want to be generic



however, Arrays.copyOf already does that for you ;-)


JDBCSupport - An easy to use, light-weight JDBC framework -
Nazma Panjwani
Greenhorn

Joined: Jan 17, 2010
Posts: 17
Thanks guys,

Joe it was an assignment, so I had to come up with my own class.....and array........couldn't use ArrayList,
Sebastian, that is exactly how I did it after discovering my original method didn't work......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: instantiation again