Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between <T> and <T extends Object> in java? [duplicate]

In Java generics, What is the advantage of using class GenericStack<T extends Object> {} over class GenericStack<T>{}.

I have implemented a generic stack using both of the above approaches but unable to trace out the difference. Help me to understand this.

like image 409
Sagar Pudi Avatar asked May 13 '15 05:05

Sagar Pudi


People also ask

What is difference between List extends T and List Super T?

extends Number> represents a list of Number or its sub-types such as Integer and Double. Lower Bounded Wildcards: List<? super Integer> represents a list of Integer or its super-types Number and Object.

What is difference between T and Object in Java?

List<T> is a name of a generic class. List<Object> is its concrete instantiation. List<T> is not a class yet (it's a generic class, a template you can create concrete classes from but not a class you can use right away), List<Object> is a class.

What does <? Super t mean in Java?

super T denotes an unknown type that is a supertype of T (or T itself; remember that the supertype relation is reflexive). It is the dual of the bounded wildcards we've been using, where we use ? extends T to denote an unknown type that is a subtype of T .

What is difference between extends and super in Java?

super is a lower bound, and extends is an upper bound.


1 Answers

There's no difference. <T> and <T extends Object> are equivalent.

like image 155
Robby Cornelissen Avatar answered Oct 24 '22 21:10

Robby Cornelissen