mahesh
mahesh

Reputation: 1633

what is this concept called and from which version of java

Can you please let me know which version of java below flower bracket ({}) is introduced? what is concept name for this.

Object[] arg =  {abc.getAbctNumber()};

here abc is object of java class and getAbcNumber() is a java method. I understand that arg object will be assigned with the value of return value of getAbcNumber() method.

Upvotes: 0

Views: 77

Answers (5)

Prateek
Prateek

Reputation: 1926

There is nothing called Flower bracket(at least I don't know about that). And in your Object[] arg = {abc.getAbctNumber()}; {} represent an array of one element and that element being an Object that is returned by method getAbctNumber()

Upvotes: 0

David
David

Reputation: 219097

This looks like a list initializer (not sure about the terminology, I don't do a lot of Java). In this case arg is an array of type Object and it's being initialized with a single value, which is the result of abc.getAbctNumber().

Consider an initializer with more than one value and it starts to become more clear:

Object[] arg = {
    abc.getAbctNumber(),
    abc.getSomeOtherNumber(),
    abc.getSomethingElse()
};

That would initialize the arg array with three elements, the results of three different methods.

Upvotes: 0

Vincent Ramdhanie
Vincent Ramdhanie

Reputation: 103155

You are creating an array with this syntax similar to:

  int myarray[] = {1, 2, 3};

which will create an array of three ints. Your array will be created with an object.

Upvotes: 1

ddavison
ddavison

Reputation: 29092

There is no such thing as a "flower bracket" in java. What you are seeing here, is an array being populated by a method.

Upvotes: 1

sandymatt
sandymatt

Reputation: 5612

{} is used to specify an array literal. So in your case you're specifying an array of objects with one element.

Upvotes: 3

Related Questions