Results 1 to 5 of 5
Thread: classes as objects
- 07-24-2009, 06:00 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 12
- Rep Power
- 0
classes as objects
hi
I want learn about this thing I see in the following example
What I don't understand is the use of the classes as though they were objects to pass to the array.
I can not even name it so could not find info about it in google.Java Code://All we do here is assemble the list of WizardPage subclasses we //want to show: Class[] pages = new Class[] { AnimalTypePage.class, LocomotionPage.class, OtherAttributesPage.class, FinalPage.class }; //Use the utility method to compose a Wizard Wizard wizard = WizardPage.createWizard(pages, WizardResultProducer.NO_OP);
Thank you.
- 07-24-2009, 09:31 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
- 07-24-2009, 09:16 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 12
- Rep Power
- 0
Does it creates an object of the class, like an instance of it?
In the example above, the function createWizard gets an array of such classes, can you help me understand how is that could be useful instead of plain instances?
does it has anything to do with reflection?Last edited by kroiz; 07-24-2009 at 09:24 PM.
- 07-25-2009, 03:29 AM #4
Member
- Join Date
- Dec 2008
- Posts
- 64
- Rep Power
- 0
It has everything to do with reflection :) when getting an instance of a Class object you are NOT getting an instance of that particular class. For instance:
The difference is the object stringClass is the actual representation of the String class whereas someString IS an implementation of the String class. What this means is the object stringClass will allow you to do things like find out what Fields the String class has for instance:Java Code:Class stringClass = String.class; String someString = "someString";
This allows you the capability to work with classes you know nothing about at runtime. Reflection is pretty powerful and fun once you learn it's uses :) Hopefully this example did not confuse you more.Java Code:Field[] fields = stringClass.getDeclaredFields();
- 07-25-2009, 05:22 AM #5
Member
- Join Date
- Jul 2009
- Posts
- 12
- Rep Power
- 0
ohhhhhh aaaaahhhh
Now I get it!
I was once asked about it in a job interview. :confused: I did not know what it was, so I got home and read about it and thought: what a useless piece of mechanism - I spent years programming in C++ without earing of it.
I was just disgruntled because I did not know. :D
I understand its usefulness now.
In the Wizard API project, I guess it is used for being able to observe the wizard's pages for changes in their fields.
Thank you all, very very much for taking the time to help me.
Have a great day.
Similar Threads
-
help with passing objects between classes
By aruna1 in forum New To JavaReplies: 7Last Post: 03-22-2009, 02:41 PM -
read txt file,with some records, create objects and store objects in tables of a db.
By stamv in forum JDBCReplies: 1Last Post: 01-22-2009, 04:25 PM -
How to get objects to interact without inheritence in separate classes?
By Fliz in forum New To JavaReplies: 1Last Post: 11-18-2008, 04:48 PM -
Objects and Classes
By Aleve in forum New To JavaReplies: 8Last Post: 12-31-2007, 08:05 AM -
Help with Objects!
By Shorinhio in forum New To JavaReplies: 1Last Post: 07-10-2007, 09:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks