aspose file tools*
The moose likes Java in General and the fly likes Initializing array through constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Initializing array through constructor" Watch "Initializing array through constructor" New topic
Author

Initializing array through constructor

Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
Hi all,
Now though we popularly know that we cannot initialize the array reference by passing the values in constructor,like:


I was thinking what was the reason behind dis-allowing this method? Is there any alternate method? 'cause otherwise there is going to be
always an additional reference in main's stack frame pointing to the array object on heap... which is kind of not a good idea.
comments please.

regards
Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

Hi,
TestArray t=new TestArray({10,20,30,40,50});


This is like The constructor TestArray (int, int, int, int, int) .





The important thing is not to stop questioning.Curiosity has its own reason for existing.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Or make it a varags parameter


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Ashutosh Limaye
Ranch Hand

Joined: Oct 24, 2005
Posts: 58
Hey Thanks guys that was useful...Great!!!
 
wood burning stoves
 
subject: Initializing array through constructor