Possible Duplicate:
What's the nearest substitute for a function pointer in Java?
I am writing a factory class to create a bunch of different widgets. For argument sake, suppose this factory can create 1000 widgets.
myWidget createWidget (widgetId)
{
case 0: createwidget0 ();
.
.
case 1000: createwidget1000 ();
}
I don't want to write 1000 cases statement. I want to put all the creation routines in an array. Use the widgetId as an index to execute the create routine directly so it does not have to go through comparing 1000 condition. So the whole createWidget routine can be simplified like this
myWidget createWidget (widgetId)
{
myAwsomeFuncArr createFunc;
myWidget widget = createFunc[widgetId] ();
}
Is there away to do this in Java ?