• 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

Getting the arguments used in a written object's constructor

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm using reflection to create instances of objects that have been written to file. I need to read what arguments have been passed into the written obect's constructor. This is what I've been doing when I know what arguments to pass into the constructor...



But now that I don't know what arguments have been passed, I can't properly instantiate the object.

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah... you mean you don't know which constructor to use? Your question as we have it so far is the same as "I have a class which might have any number of constructors, how do I know which one to choose?" Notice that we out here know nothing about the class you're trying to create an object of.

So, you're going to have to write code which gets that list of classes from somewhere else in your program. In other words you're going to have to modify the design of your program so that information is passed to this code.

By the way line 1 in your second example can be simplified to this:

 
Brendan Thompson
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's one of two constructors. But before the object was written to file, it had already been instantiated and the code was ready to be executed. The program then went through a shutdown and the object was saved so it can be used when the program is restored. Now I want to know what exact arguments were passed to this object before it was saved, so I can instantiate it the same was as before. Hope this makes sense.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic