Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic syntax for extends or equal to

Tags:

java

generics

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

Thanks, Adam.

Update:

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...

Adam.

like image 342
TacB0sS Avatar asked Jan 28 '26 03:01

TacB0sS


2 Answers

You already got it:

GenericExample<ItemType extends MyObject>

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

like image 84
Nicolas Avatar answered Jan 29 '26 17:01

Nicolas


GenericExample<T extends Object>
like image 28
GriffeyDog Avatar answered Jan 29 '26 16:01

GriffeyDog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!