This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array Shortcut Notation as a Method Parameter

 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works:



...as does this:



This does not:



The latter gives me a compiler exception stating that the method setParameters(String[]) is not applicable for the arguments (String, String, String).

Any ideas as to why the shortcut syntax is not allowed when used as a parameter to a method?

On a side note, I've gotten around the issue by changing the signature of generator.setParameters to be:



That allows me to do this:



I'm just curious why the notation above doesn't work in that scenario. Thanks.
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
generator.setParameters({"server_name=server","db_name=dbname","dictionary_table_name=dd"});

This type of pattern is legal only during the initialization of Objects...
 
Paul Clapham
Sheriff
Posts: 20711
29
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram Narayan.M wrote:This type of pattern is legal only during the initialization of Objects...


That's right; for something even more surprising try this:


You'll find that doesn't compile because the second line doesn't initialize anything.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic