I am developing a ComboBox (more for context than actual significance), and I would like to know if the "or" operator exists in Java generics. For now, the declaration looks something like that:
public class SComboBox<T extends ComboBoxItem> extends JPanel {
Where ComboBoxItem is an interface I created for items that can be used in the ComboBox. However, I'd also like to accept String as a type, which seems like a difficult task since:
Stringis afinal classso there's no way anyone could extend it.- I am not sure if you can put either something like "|" (or) operator, or just outright specify an acceptable class. Since there is an "and" operator (
<T extends A & B>) I imagined it would make sense to have the "or" (|) as well.
My question is essentially point 2. Can I, in generics, specify a class I want to accept and/or use something like a "|"? If not, is there any workaround or should I ditch the idea of using generics?