0

I just got Strings (out of a database), which are not even the names of the objects (but properties of them) and have to work on these classes and objects.

EDIT: To make things clear: I got 1 jar (the programm core), in which i load/open many different jar-file. In the core, i got a class which is accessing a database with all classnames and classobject-properties (not the objectnames, but properties of the objects) of all other jar files, saved as Strings.

Now i want to get access to the Objects in the jars by using these Strings. First I call the classloader with the classnames.

Now i want to open/load another jar out of this jar and transfere data to it. Like jumping from one jar to another jar.

There are many problems in it, which are confusing me. For example i cant edit the contructors(/or create new ones), because it would destroy the functionality of our software.

Question: Is there a way to get the real objects with just using Strings? Would love to find a way around Reflections.

huidube
  • 390
  • 3
  • 15
  • See: http://stackoverflow.com/questions/194698/how-to-load-a-jar-file-at-runtime – Moritz Petersen Oct 20 '14 at 12:56
  • how is this related to my problem? Can you give me a small hint? – huidube Oct 20 '14 at 12:59
  • 1
    Your question lacks entirely what you are actually doing using Reflection, therefore there is no way of telling whether there is an alternative to that. Think about your code examples. E.g. what is the snippet telling us that you are creating a `Frame` *supposed* to tell us? Or, why are you telling us that you have *two* jar files? Has it a relevance? (normally it doesn’t) – Holger Oct 20 '14 at 13:30
  • i completly overhaulted my question. – huidube Oct 20 '14 at 14:21

1 Answers1

0

I think you main choices are to:

  • Use reflection
  • Access the Dog instance object by referring to it as an Animal object (your base class), and override the desired methods in Dog.
  • Make all classes such as Dog implement an interface

The base class method and the interface method both mean you will have to plan out your desired properties, and then make each implementing class fit into that model.

If you do add the methods to Animal or a new interface, you would want to convert your object fields (eg., hairLength) to getters (int getHairLength();) and setters.

In your code, you can always use the instanceof operator to see if the unknown object implements or derives from your known class.

Jamie
  • 1,888
  • 1
  • 18
  • 21
  • thank you for your answer. As i cant edit the jar-files as they are changing dynamically, i dont see a way how this can help me. My question was specified on the work with String databases. – huidube Oct 20 '14 at 13:49