| Article: |
Creating Varargs in Java 1.5 Tiger | |
| Subject: | Are varargs an improvement? | |
| Date: | 2004-08-14 20:30:22 | |
| From: | MarcinJeske | |
|
I have read a number of articles and comments lauding varargs as one of the best new features in 1.5. I don't get it. They just seem to be a slight change of syntax and a change to coding style. Further, while they save some people a bit of typing, they introduce potentially elusive bugs (as noted in the excerpt).
|
||
Showing messages 1 through 2 of 2.
-
Are varargs an improvement?
2004-08-19 06:36:52 Brett McLaughlin |
[Reply | View]
Marcin-
Thanks for your comments. I think it's true that varargs have been pretty heralded in Tiger. That said, I've always maintained (or tried to maintain) that they are more about convenience than functionality.
I think what you'll find is that many Java programmers, especially ones for which Java is their first language, really aren't as comfortable as you might think with arrays. It's simply easier to works with Java collections. For these reasons, the idea of converting arguments to an array is a bit of a pain.
And, I do think there are valid uses of varargs, like the classic max(int...) type of method. It really is a pain to throw ten or fifteen variables into an array just to call a method like this (max int[]), at least in my opinion.
All that said, you're very much right that varargs can introduce a lot of hinky bugs. Like almost any new feature, it will probably be overused until some well-defined usage patterns develop. But, that's to be expected with new APIs :-)
Thanks for your comments!
-Brett McLaughlin




If you are seeing the Java 1.5 new features, ut will reduce the work for programmers rather than focusing on more functionality.
But generics are realy amazing feature indeed.using enumerationa and varargs and static imports are minmize the code.
Correct me if i am wrong.
Thank you.