• Post Reply Bookmark Topic Watch Topic
  • New Topic

What would happen if "newInstance()" method from class Class were defined as static in Java API  RSS feed

 
Rajiv KumarRai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to know that why was "newInstance()" method defined as non-static.. what difference it would make if
it was a static method?

Thanks
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Err ... the newInstance() method would not know what class of instance to create! Is this a homework question ?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use that method as a factory method and call Class.newInstance(Foo.class)

But that is how the designers of Java™ wanted it to work: create a Class object and call the method on it. That is the object‑oriented way to do things.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!