开发者

check reference class type at compile time

If I have some type decla开发者_高级运维rations like:

JCheckBoxMenuItem t1;
JRadioButtonMenuItem t2;

and then a method like

addItem(JMenuItem i)
{
}

can I know if i is a JCheckBoxMenuItem or a JRadioButtonMenuItem type without having an instance of them when I call it with addItem(t1) or addItem(t2) ???


If you need different behaviour based on the type of the object, don't use the same method. Make different methods, accepting different argument types.


Well, you can always call t1.getClass(), whhich will give you the effective class of the input object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜