• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static Factory Methods in java  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can anybody throw some Light regarding Static factory Methods in java .

In one of the book, i gone through , the author is mentioning that Arrays.asList can be taken as an example for Static Factory Method .


Thanks in advance .
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It comes from a well known design pattern called the Factory Method. I wouldn't call Arrays.asList a factory method though. It justs transforms an array into a List.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what do you want to know? See: Factory method pattern

A factory method is a method that's called to create some object. Factory methods are often static. One example of a static factory method is Calendar.getInstance() - it returns an instance of some subclass of the abstract class Calendar. The idea is that you don't need to know exactly what the subclass is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!