About Question enthuware.ocajp.i.v7.2.1207 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
coder007
Posts: 25
Joined: Wed Dec 17, 2014 9:29 pm
Contact:

About Question enthuware.ocajp.i.v7.2.1207 :

Post by coder007 »

Second option

Code: Select all

new Object[]{ "aaa", new Object(), new ArrayList(), {} };
you did say:
{ } doesn't define any kind of Object.
But why this is legal when we initialize 2-dimensional array?

Code: Select all

Object arr[][] = new Object[][] {new String[], {} };

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1207 :

Post by admin »

{ } in your case is part of a syntax for an array definition. You can also do something like String[] sa = { }; and this would define a String[] object. That is just something that the language designers have allowed in the language.

But it is true that { } on its own means nothing at the least and creating a new scope at the most. It doesn't define any object as such. You cannot just write { } and expect to have an object (which is what the code in the given option expects.)

On a second thought, I think you are right. The statement "{ } doesn't define any object" is not clear enough. It should be improved.

thank you for your feedback!
Paul.

zevsnoe
Posts: 3
Joined: Sun May 03, 2015 6:12 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1207 :

Post by zevsnoe »

Hi Admin,
in your explanation
Object arr[][] = new Object[][] {new String[], {} };
will not compile since new String[] is not valid array initializer - it should contain size or elements, so sth like
new String[5] or new String[]{"string"} would work
Please fix, tnx

admin
Site Admin
Posts: 10389
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1207 :

Post by admin »

Fixed.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests