|
Problem:
You want to use a class as if it were an object. Solution:
You can't. What you probably meant to do was make a new object, and use that:
Discussion: In the last recipe, we noted that object instances could be used as classes, in the sense that you could call class methods on objects and expect it to Do The Right Thing. The inverse is not true. If you're calling an instance method on a class name, you're probably doing something wrong, because there is no "object" for the method to operate on. Calling an instance method via a class name therefore causes an exception. Keep in mind that a class is merely a definition of what it means to be an object of a certain type; it doesn't actually create an object, unless and until you ask for one to be created.
|