java declaration not clear

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nilotpal sarkar
    New Member
    • Feb 2012
    • 2

    java declaration not clear

    I got a declaration like this.

    Object obj=constructor .newInstance(ne w 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.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    It's just a short cut of
    [code=java]
    Object[] objectArray = new Object[] {"abc"};
    Object obj=constructor .newInstance(ob jectArray);
    [/code]
    Now,
    [code=java]
    Object[] objectArray = new Object[] {"abc"};
    [/code]
    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
    [code=java]
    int[] rzero = new int[5];
    rzero[0] = 0;
    rzero[1] = 3;
    rzero[2] = 5;
    rzero[3] = 1;
    rzero[4] = 9;
    rzero[5] = 8;
    [/code]
    Or the shortcut

    [CODE=java] int[] rzero = new int[]{0,3,5,1,9,8};[/CODE]

    Comment

    Working...