• Post Reply Bookmark Topic Watch Topic
  • New Topic

Load an object runtime  RSS feed

 
King Amit
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!