Saw on Blogtime Exception a topic on how var args can be used to emulate named parameters. With HostedQA and BigBark, I wrote a DAO wrapper around iBatis that did something similar.
For example:
dao.find(”byNameOrEmail”, “Patrick”, “foo@example.com”)
Since I am using iBatis, I don’t generate the SQL, but I do figure out the query name dynamically (in this case it would be selectByNameOrEmail) and construct the named parameters as so (name -> “Patrick”, email -> “foo@example.com”).
This is a great technique that can help Java limp by as long as it doesn’t have named parameters.
Update: Duh. I forgot that a new project, ParaNamer was recently created to try to address similar issues. Check it out.
0 Comments on “Var args and Java’s lack of named parameters”
Leave a Comment