Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Difference between List of ? (any type) and List of Object in Java Generics

Difference Between List Of ? (any Type) And List Of Object  In Java Generics
No doubt that Generics is one of the most confusing topics in Java and you can easily forget concepts and rules, especially, if you don't code Java everyday. For example, both List> and List looks similar but there is a subtle difference between them, the List> is basically a list of any type, you can assign a list of String i.e. List or list of Integer i.e. List to it. You see the point, it uses the unbounded wildcard >, which means any type. It provides it the much needed Polymorphism require while writing Generic methods. Basically, if your method has a type List> which means you can pass any type of List to it but remember the type is unknown, until you assign it i.e. List> myList = new List(). 


This post first appeared on Javarevisited: Blog About Java Programmin, please read the originial post: here

Share the post

Difference between List of ? (any type) and List of Object in Java Generics

×

Subscribe to Javarevisited: Blog About Java Programmin

Get updates delivered right to your inbox!

Thank you for your subscription

×