Wednesday, July 13, 2005

Less Code

Started the first go of using generics in JRDF. It uses Java's collections pretty heavily so there's quite a lot of work to be done. Many good things happened, mostly it's less code - casting went away (of course) and things like add became type safe. It makes a lot more sense to add/remove an org.jrdf.graph.ObjectNode to a Bag rather than an java.lang.Object.

One thing I have yet to do (and see if it's even possible) is to see whether things like addAll, containsAll, etc can be made to use more specific variants (Alternative, Bag, etc) rather than Collection. From what I've gathered so far it may not be possible for backwards compatibility reasons. It seems like what I want (and what Java generics needs apparently) is variant types.

Tom has some comments on 0.3.4 too.

Update: In some instances (pun intended) there's more code: How do I generically create objects and arrays? and How do I perform a runtime type check whose target type is a type parameter? "For a type check at runtime we must explicitly provide runtime type information so that we can perform the type check and cast by means of reflection. The type information is best supplied by means of a Class object."

No comments: