扩展等于的通用语法 [英] Generic syntax for extends or equal to

查看:59
本文介绍了扩展等于的通用语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GenericExample< ItemType(扩展或等于)Object >在Java中的语法如何?

How is the syntax in Java for GenericExample<ItemType (extends or equal to) Object>?

谢谢, 亚当.

更新:

感谢您的所有答复. 这里的答案与代码中泛型的使用有关,我想讨论一下减速的实现,例如:

Thanks for all your replies. The answers here are more related to the use of the generics in code, I would like to discuss the deceleration implementation, for example:

class GenericExample<ItemType (extends or equal to) ParentType> {
}

class Inherited<ParentType> extends GenericExample<ParentType> {
    /* The type parameter in this class does not compile.
       I would like to find a work around to make something like this to work. 
       I would like to have ParentType=JComponent , and thus to specify that the  
       Inherited class uses JComponent for needed flexibility*/
}

我希望这更有意义...

I hope this makes more sense...

亚当.

推荐答案

您已经知道了:

GenericExample<ItemType extends MyObject>

可以在此处找到有关泛型的第一指南: http://download.oracle.com/javase/1.5.0/docs/guide/language/generics.html

A first guide on generics can be found here: http://download.oracle.com/javase/1.5.0/docs/guide/language/generics.html

这篇关于扩展等于的通用语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆