| | |
Weird Question
Thread Solved |
Then I was correct in my last response.
Again, in Ruby, what you just described would look like this:
Again, in Ruby, what you just described would look like this:
Ruby Syntax (Toggle Plain Text)
button_name = "button1" eval(button_name).whatever # calls whatever() on the variable button1
> It just lets me know about certain properties of an Object, such as its classname
It does much more than that.
> The concept of a Map is somewhat familiar, but it doesn't help avoid the work, does it?
It provides a solution to your problem. IMO, what you are looking for is not a solution but a syntactic sugary way of doing things. Like previously mentioned, either use an array, a map or a JVM targeted scripting language like maybe Groovy, Scala, Rhino etc.
> I guess this isn't possible in Java though.
Yes, in the same way it isn't possible to create classes in C.
It does much more than that.
> The concept of a Map is somewhat familiar, but it doesn't help avoid the work, does it?
It provides a solution to your problem. IMO, what you are looking for is not a solution but a syntactic sugary way of doing things. Like previously mentioned, either use an array, a map or a JVM targeted scripting language like maybe Groovy, Scala, Rhino etc.
> I guess this isn't possible in Java though.
Yes, in the same way it isn't possible to create classes in C.
I don't accept change; I don't deserve to live.
•
•
Join Date: Sep 2008
Posts: 1,580
Reputation:
Solved Threads: 200
I don't know all that much on reflection, but I have used it before. I don't see how it is useful. I've seen plenty of examples of reflection, so I understand how it is used. Just not why. Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why? All the tutorials I see give examples of reflection, but they are never situations where reflection is necessary. For example, I saw reflection being used to print out hello world. Pointless.
Think of all the frameworks which let you specify your custom class in their configuration file and load those classes at runtime. The servlet specification for instance has a deployment descriptor which allows the developer to configure servlets, filters for his application. All the developer has to do is to specify the class name and the required processing is done at runtime by the container.
Also look into Spring or Guice which are IOC/Dependency Injection frameworks.
That being said, there *are* a lot of uses of reflection; it's just that they aren't that obvious.
Also look into Spring or Guice which are IOC/Dependency Injection frameworks.
That being said, there *are* a lot of uses of reflection; it's just that they aren't that obvious.
I don't accept change; I don't deserve to live.
•
•
Join Date: Nov 2008
Posts: 19
Reputation:
Solved Threads: 6
If you make your object Serializable then you can store information about the object in String form. It won't be as readable as "germanShepard" but you could store objects serials somewhere to enter. Doesn't sound too practical.
Another thing you can do is make a factory class. The class would take certain strings and generate objects for you to use based on that string name. It's a common design pattern and I've seen it used while poking around with code at work.
Another thing you can do is make a factory class. The class would take certain strings and generate objects for you to use based on that string name. It's a common design pattern and I've seen it used while poking around with code at work.
•
•
Join Date: Sep 2008
Posts: 1,580
Reputation:
Solved Threads: 200
•
•
•
•
If you make your object Serializable then you can store information about the object in String form. It won't be as readable as "germanShepard" but you could store objects serials somewhere to enter. Doesn't sound too practical.
Another thing you can do is make a factory class. The class would take certain strings and generate objects for you to use based on that string name. It's a common design pattern and I've seen it used while poking around with code at work.
bionic: Making objects Serializable means you can write the objects to file in Binary form and read them back in this way, so that you can store and retrieve your Objects more easily than if you were to do text input and output. Maybe I misunderstood what you said, but it's actually much more practical than reading/writing Strings to a file.
Regarding your other point, you can also take Strings and make objects by using a simple if statement, so I don't see why that would be a good use of reflection.
> Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why?
We use it on our current project for dynamic configuration of our UI. All panel components share an interface and with a simple XML file we can reconfigure the frames and panels with no change to the compiled jar file. We also use it for our reporting engine to load column classes that can be plugged in to our table-based reports. These are simple usages of loading classes that share a common interface by supplying their class name and other properties in simple xml files.
We use it on our current project for dynamic configuration of our UI. All panel components share an interface and with a simple XML file we can reconfigure the frames and panels with no change to the compiled jar file. We also use it for our reporting engine to load column classes that can be plugged in to our table-based reports. These are simple usages of loading classes that share a common interface by supplying their class name and other properties in simple xml files.
•
•
Join Date: Nov 2008
Posts: 19
Reputation:
Solved Threads: 6
•
•
•
•
> Can anyone provide a reasonable example of a situation that needs reflection and a short explanation of why?
We use it on our current project for dynamic configuration of our UI. All panel components share an interface and with a simple XML file we can reconfigure the frames and panels with no change to the compiled jar file. We also use it for our reporting engine to load column classes that can be plugged in to our table-based reports. These are simple usages of loading classes that share a common interface by supplying their class name and other properties in simple xml files.
![]() |
Similar Threads
- driver_irql error question (Windows NT / 2000 / XP)
- Straight C (C++)
- HAELP! Fixed vundo and now have no desktop. (Viruses, Spyware and other Nasties)
- Access Control Exception vs. Applet Viewer (Java)
- Quick directory question (C#)
- system restarts by itself...and more weird things (Windows NT / 2000 / XP)
- Weird, weird problems with fstream (C++)
- IE "can't find server" after loading home page (Viruses, Spyware and other Nasties)
- Uber-N00B question (C++)
- What is BRIDGE.DLL (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Printing output of an array
- Next Thread: How would you go about coding this?
| Thread Tools | Search this Thread |
add android api applet application applications array arrays automation bank binary bluetooth chat class clear client code codesnippet collections component converter database development dice digit eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jni jpanel julia linux list loop looping main map method methods mobile myregfun mysql netbeans newbie nonstatic openjavafx parameter pearl php print problem program programming project recursion repositories scanner scrollbar server set size sms sort sorting spamblocker sql sqlserver state storm string superclass swing swt text-file thread threads tree windows






