aspose file tools*
The moose likes Beginning Java and the fly likes is this instance an attribute of another instance? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "is this instance an attribute of another instance?" Watch "is this instance an attribute of another instance?" New topic
Author

is this instance an attribute of another instance?

Dorcas Rebanha
Greenhorn

Joined: Apr 04, 2007
Posts: 18
In the application, the class CropStipulation has a description, which is of type String, and it has a transaction which is of type TransactionDeclaration.

In the same application, the class ProgramStipulation has a String description, and it also has a transaction of type TransactionDeclaration.

There is nothing in TransactionDeclaration to indicate when it is an attribute of a CropStipulation or when it is an attribute of a ProgramStipulation.

Is there a method (or something? anything?) that will allow me to determine where a given instance of TransactionDeclaration is from?

Thanks.

Dorcas
ronnir paterl
Greenhorn

Joined: Oct 18, 2007
Posts: 11
U can use instanceof to check the class of your object


e.g
if (object instanceof class)
/// your statements here


hope this helps...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Dorcas Rebanha:

Is there a method (or something? anything?) that will allow me to determine where a given instance of TransactionDeclaration is from?


No; there's no way within Java to determine from where an object is referenced. Remember that although it may not be possible in your application, it's possible in theory for a single object to be an instance variable in several other objects.


[Jess in Action][AskingGoodQuestions]
Dorcas Rebanha
Greenhorn

Joined: Apr 04, 2007
Posts: 18
(sigh)
I was afraid of that. Thanks, anyway.

Dorcas
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
That's actually one of the cool things about OO (and good modularity in any language.) An object doesn't depend on how it's used, so other folks are free to come up with creative new uses. If you had code that said:

you'd have to modify that code every time you used it in a new place. Back in the previous millennium I worked with COBOL programs that had that dependency and it was way ugly.

You said "I was afraid of that" which hints at some other problem you're trying to solve. What's up? Maybe we can help.
[ October 19, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
 
subject: is this instance an attribute of another instance?