• 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

Load an object runtime

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello Guys,

I have a small doubt.
Is there anyway to get an object on runtime.

Something like this:
I have a class say Employee and has following properties name, addrees, id

Now i have an object of Employee but I have to get one of the property depending on certain conditon.

So it may be emp.getName() or emp.getID on runtime.

How do I achieve this?


Regards,
Amit
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

King Amit wrote:
Hello Guys,

I have a small doubt.
Is there anyway to get an object on runtime.



That's the only way to get an object.

Something like this:
I have a class say Employee and has following properties name, addrees, id

Now i have an object of Employee but I have to get one of the property depending on certain conditon.

So it may be emp.getName() or emp.getID on runtime.

How do I achieve this?



It's hard to say without more details. Depending on your specific requirements and use cases, it might be as simple as


Or it might be that you'll want to use reflection or JavaBeans property introspection to get a property based on its name that isn't known until runtime.
 
King Amit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No its not that simple actually.

There are hundred of properties and too multilevel.

I have to use these properties to be compared for their values depending upon what property user selects at runtime.

so it may be emp.getName.getLastName
or if he chooses country's zip code
it would be emp.getCountry.getState.getZipCode()

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, again, there's not much detail to go on, but based on what you've said, it sounds like a candidate for reflection or introspection.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are we talking about Java objects serialized somewhere that you want to read in and query?

It is really very simple if serialized objects are stored in a Serializable collection.

Bill
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic