Slight correction... say you are talking about a class named com.acme.whizbang.SpiffyThing:
does not return a "SpiffyThing" object.... it returns a java.lang.Class object... in other words, an instance of the class "java.lang.Class".... that object represents the class com.acme.whizbang.SpiffyThing, in the same way that an Integer object can represent an int value, or a Double represents a double. The Class object has methods to get information about the SpiffyThing class. It also has the following method:
The Class method newInstance() is a way to instantiate (get an object of) a class when you don't know the name of the class until runtime (for example, maybe it came out of a database). A lot of times, this is the only reason you need the Class object, so those two lines are combined into one (and no reference to the Class object is kept):
That works out to be the same as:
Anyway, if you're at the point in your understanding where you're not clear about the distinction between classes and objects, just be aware that java.lang.Class exists, and that it can be a source of confusion.
class - blueprint for, or type of, object object - a manifestation of the blueprint instance - synonym for Object
Hope this helps -- Jon
Joined: Mar 24, 2004
ok, timing of my last reply looked like I was addressing Stan's post, but I just type slowly ;-).
Now I am addressing Stan's post.
This should have been (bolded where it is changed):
Shyam Prasad Murarka
Joined: May 02, 2005
Dear Readers, Thanks very much! I now have a clear understanding of this topic.
Joined: Jan 29, 2003
Jon, thanks for the corrections. I got caught between thinking myClass was a variable and a string name.
subject: difference between instantion and object.