File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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.

Vijay Tidake
Ranch Hand

Joined: Nov 04, 2008
Posts: 146

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!!!
I agree. Here's the link:
subject: Initializing array through constructor
jQuery in Action, 3rd edition