By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,804 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,804 IT Pros & Developers. It's quick & easy.

java declaration not clear

P: 2
I got a declaration like this.

Object obj=constructor.newInstance(new Object[] {"abc"});
//constructor is a object of Constructor class(using reflection)

i am not clear with the declarartion like this.can some1 explain what is in the brace{"abc"}, as well as the complete declaration in detail.
thanx in advance.
Feb 20 '12 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
It's just a short cut of
Expand|Select|Wrap|Line Numbers
  1. Object[] objectArray = new Object[] {"abc"};
  2. Object obj=constructor.newInstance(objectArray);
  3.  
Now,
Expand|Select|Wrap|Line Numbers
  1. Object[] objectArray = new Object[] {"abc"};
  2.  
Is itself a shortcut of creating a new array and populating it at the same time.
e.g if I wanted an array with the integers 0, 3, 5, 1, 9 I could do it as follows
Expand|Select|Wrap|Line Numbers
  1.         int[] rzero = new int[5];
  2.         rzero[0] = 0;
  3.         rzero[1] = 3;
  4.         rzero[2] = 5;
  5.         rzero[3] = 1;
  6.         rzero[4] = 9;
  7.         rzero[5] = 8;
  8.  
Or the shortcut

Expand|Select|Wrap|Line Numbers
  1.  int[] rzero = new int[]{0,3,5,1,9,8};
Feb 20 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.