Any suggestions on a good way to implement templates in java?
The normal way to implement template behavior
in Java is to create an interface defining the
common behavior that is being abstracted. Every
class that would normally would be instantiated
as a template in C++, would have to implement
this interface in Java. A good example of this
is the java.lang.Comparable interface in JDK 1.2.
You can write a single sort method to sort
any object implementing the Comparable interface,
rather than writing N different sorts. However,
you will find that this approach is not sufficient
to achieve all of the benefits of C++ templates.
You may consider doing a search on the web for
an experimental Java compiler called Pizza, which
implements extra functionality like templates.