File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Devaka's Final Exam Question.

 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have doubts in Line 1 as marked above.
In line 1 even if I change the statement to static void capture(Long[] x){
System.out.print("F");
}
Then I get compiler Error. Why does that happen? Considering Long[] x and Long ... x are considered to have the same method signatures??
 
Abhishek Bhat
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi Abhi,

The answer to your question lies in the names of the two concepts. One is an array, meaning, a GROUP and the other is VAR-ARGS which means Variable arguments, implying, the length of the ARGUMENTS can VARY. so if you have a NO-ARG method or a method with a certain number of arguments, the VAR-ARGS would accept it happily . THIS purpose however, cannot be fulfilled by an ARRAY . I beleive because of this inefficiency of the Array, the var-args concept was introduced by the designers . I hope you understood ..

Let me re-iterate, the difference lies in the names itself...

Gud luck !
 
Stephen Davies
Ranch Hand
Posts: 352
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quite simply an Array and a Varargs are two different specific things. An array holds a collection of objects (or references to) and Varargs (variable [amount of] arguments) is a parameter of what you can enter to the argument. Varargs reduce the need to overload in that it provides the ability to enter any number of arguments. As you can see they are indeed different items!


Hope this helps to!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic