Your current code can easily lead to invalid states (e.g. ComponentWrapper<SomeComponentThatIsNotAJLabel> that wraps JLabel ), and probably why the compiler will stop you there. Instead, you should use the static method:
public static ComponentWrapper<JLabel> wrapLabel(final String title) { return new ComponentWrapper<JLabel>(new JLabel(title)); }
Which would be much safer in many ways.
source share