When would one ever use the Method class?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

When would one ever use the Method class?

 
0
  #1
Jun 3rd, 2008
I looked up the method class and thought that it might be useful, but unfortunately Method objects must be public to be invoked.

I'm just curious of when I'd actually really need to use the Method class. Maybe to create an array that used a type of algorithm to fire different methods?

Sorry if this is too vague. I'm just really curious.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 224
Reputation: bugmenot is an unknown quantity at this point 
Solved Threads: 31
bugmenot bugmenot is offline Offline
Posting Whiz in Training

Re: When would one ever use the Method class?

 
0
  #2
Jun 3rd, 2008
Reflection. you need it when you want to invoke a method by reflection. A method does not have to be public to be invoked. However, you will need to know how to get it. (Class.getMethod() will not work, it only works for public methods; Class.getDeclaredMethod() will work)
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: When would one ever use the Method class?

 
0
  #3
Jun 3rd, 2008
I'm not quite familiar with java.lang.Reflect , honestly I've only dabbled with that class through experimentation.

I.E., when it came to creating generic-based methods.

What is the primary usage of the Reflect package?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3
Reputation: dkerberwra is an unknown quantity at this point 
Solved Threads: 0
dkerberwra dkerberwra is offline Offline
Newbie Poster

Re: When would one ever use the Method class?

 
0
  #4
Jun 3rd, 2008
Originally Posted by Alex Edwards View Post
I'm not quite familiar with java.lang.Reflect , honestly I've only dabbled with that class through experimentation.

I.E., when it came to creating generic-based methods.

What is the primary usage of the Reflect package?
You use the reflection classes when the classes and/or methods you want to use are not known at compile time. For example, you can specify class and method names as strings based on some user input, and instantiate the classes and execute the methods from there.

I use it for report generation, when the report layout depends on what state the user is in (retrieved from a database). The basic data is the same, so each state's version is just a subclass of a more generic report class.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC