• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

is this instance an attribute of another instance?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U can use instanceof to check the class of your object


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


hope this helps...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Dorcas Rebanha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(sigh)
I was afraid of that. Thanks, anyway.

Dorcas
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic