I am currently writing a program using Weka that builds a model (using one of the various model types included in Weka). The part I'm having trouble with is that I want to allow the program to use multiple types for the same function. For example, if I choose to use a J48 decision tree, I need to build and call functions on a variable of type J48. On the other hand, if I want to use a BayesNet I need to build and call the same functions on a variable of type BayesNet. This model needs to be used at different points of the program, and so a simple if-else chain won't do.
Essentially what I need is the equivalent of a void pointer in C++. Something that can take on various types that can all perform a similar function. I'm tried using the generic Object class but found it was not able to be casted to the correct type (I got "incompatible type" errors).
So, the short version of my question is this: How do Java programmers solve the problem that C++ programmers would solve with void pointers?
Thanks, -Morag