I want a Generic Method, however I'm not sure if it's ideal for this scenario, nor am I very much familiar with how Generic's work (if someone could link me a good tutorial or article, I'd very much appreciate it.)
However, I wanted to create a method that handles initialization of JComponents, and if the array of JComponents was All JRadioButtons, to be sent to a different method.
public void initializeComponent(JComponent...components)
{
if(components[0] instanceof JRadioButton)
initializeJRadioButtons(components[]);
}
However, this will only check whether the first one is a JRadioButton, I feel Generics may handle this better, but is there a way to check if all components are JRadioButtons without looping?
Such as if someone does this.
JRadioButton[] radioButtons = new JRadioButton[2];
...
initializeComponent(radioButtons);
instanceoftest and delegate toinitializeRadioButton(no plural) for each component? Do you need to initialize arrays of components at once? I don't see how generics would help you do that.JRadioButtoninit(Foo... foos),init(Bar... bars), etc.?