fsteeg.com | notes | tags

∞ /notes/trees-with-generics-and-visitors | 2007-12-31 | java programming

Trees with Generics and Visitors

Cross-posted to: https://fsteeg.wordpress.com/2007/12/31/trees-with-generics-and-visitors/

Using generics and the visitor pattern, it is actually possible to define a generic tree for different objects and different operations on the tree, I have learned from the very interesting book Java Generics and Collections. This seems quite useful to me. I have added an implementation for general trees based on the binary tree implementation in that book to the Literate Programs wiki. Now what gets me thinking is that I have read someone (think it was sma) writing the visitor pattern is superfluous. Could that be meant as in 'for certain languages, where visiting can be done very naturally'? Then this would still all make sense for Java.