aspose file tools*
The moose likes Beginning Java and the fly likes How to reference an Object in main from a called method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to reference an Object in main from a called method" Watch "How to reference an Object in main from a called method" New topic
Author

How to reference an Object in main from a called method

Laura Wells
Greenhorn

Joined: Sep 14, 2005
Posts: 12
I have some code that will pass in a couple of parameters and call a method. This method will get parent/child objects.

The web page is a list of reports and I want to return the report object for each one when the report title ends with "Revenue per Day".

How do I reference the CurrentObject that is returned from the called method (inside of the main loop)?

[ September 26, 2005: Message edited by: Michael Ernest ]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

So if you use an object reference reportLink to talk to a GuiTestObject in memory, you can make whatever calls on it you like that are supported by the GuiTestObject's interface. It would just be reportLink.whicheverMethod(whicheverargs) as described (hopefully) by the accompanying documentation.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Laura Wells
Greenhorn

Joined: Sep 14, 2005
Posts: 12
Thanks for the feedback.
I have a follow up question ... why would it be "reportLink"
rather than "CurrentObject" which is the object I'm returning?
reportLink.whicheverMethod(whicheverargs)"

Shouldn't I need to reference it by the object name I'm returning?

Laura
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Not at all. The name 'CurrentObject' is local to the called method; it's declared and used within the method. Therefore once the method completes its run, the CurrentObject reference will go away.

In the body of your main method, what your code calls 'reportLink' is another reference name that points to what CurrentObject pointed to. If for clarity's sake you wanted to change the name 'reportLink' to 'CurrentObject' you could do that.
Laura Wells
Greenhorn

Joined: Sep 14, 2005
Posts: 12
getChildObject is the method name....correct?
Laura Wells
Greenhorn

Joined: Sep 14, 2005
Posts: 12
Thanks for the info on the CurrentObject reference. That makes sense.
 
Don't get me started about those stupid light bulbs.
 
subject: How to reference an Object in main from a called method