aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes return type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "return type" Watch "return type" New topic
Author

return type

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
if the return type of a method is list...cant we return an arraylist? after all an arraylist is a list?
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

yes offcourse!!


SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
Actually if the return type is List we cant assign it to a arraylist....i got it now
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

yeah right, even you cannot return something like
return new List()
because list is an interface you have to return one of its implemented class
Set/ArrayList/LinkedList and so on...
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
If you see javadocs, ArrayList implements the interface List.

So basically we can say something like





Perfectly legal. Any interface subtype can be returned.


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return type