Posts

Showing posts from 2009

Considering using Java Variable Arguments

one day i came across this situation, we have a Java project (LoggerCore) which is a common project used by many other projects. I had to modify a method signature in LoggerCore project, but was afraid that i would end up cascading changes in all the projects to satisfy java compiler. Started thinking that there should be someway to modify my project and common projects with out touching other projects which also use this common one. Suddenly it flashed while driving home, Java Variable Arguments. Let us have look at the code snippets: public SpringBrainLogger logIt(String referenceNumber) { ... } This is the original method signature in LoggerCore project, if I have to pass extra information, i need to add new argument and add it through out its reference. How tedious? Easily error prone! public SpringBrainLogger logIt(String referenceNumber, LogInfo... info) { ... } Intead, I considered doing this. I added LogInfo... info which is Java variable argument syntax. Boon: - Dont hav