-
Enhancement
-
Resolution: Not an Issue
-
P4
-
7
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
If a generic JComboBox<E> is created, getSelectedItem() should have return type E.
JUSTIFICATION :
JComboBox is incompletely generified.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JComboBox<String> jcb = new JComboBox<>();
jcb.addItem("Hello");
String str = jcb.getSelectedItem();
should compile without errors.
ACTUAL -
error: incompatible types
required: String
found: Object
---------- BEGIN SOURCE ----------
package com.xyz.test;
import javax.swing.JComboBox;
public class Test
{
public static void main(final String args[])
{
JComboBox<String> jcb = new JComboBox<>();
jcb.addItem("Hello");
//String str = jcb.getSelectedItem(); // error: incompatible types
// required: String
// found: Object
String str1 = jcb.getItemAt(jcb.getSelectedIndex()); // OK
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
getItemAt(jcb.getSelectedIndex());
If a generic JComboBox<E> is created, getSelectedItem() should have return type E.
JUSTIFICATION :
JComboBox is incompletely generified.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JComboBox<String> jcb = new JComboBox<>();
jcb.addItem("Hello");
String str = jcb.getSelectedItem();
should compile without errors.
ACTUAL -
error: incompatible types
required: String
found: Object
---------- BEGIN SOURCE ----------
package com.xyz.test;
import javax.swing.JComboBox;
public class Test
{
public static void main(final String args[])
{
JComboBox<String> jcb = new JComboBox<>();
jcb.addItem("Hello");
//String str = jcb.getSelectedItem(); // error: incompatible types
// required: String
// found: Object
String str1 = jcb.getItemAt(jcb.getSelectedIndex()); // OK
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
getItemAt(jcb.getSelectedIndex());