sixtytrees sixtytrees - 1 year ago 39
Java Question

How to read a variable structure in Java?

I try to extract relevant information from a bundled object in Java. This object has a structure:

String name;
Array setOfOrders;

Each element in setOfOrders has

int orderID;
String orderName;
List<BuildingBlock> listOfBlocks;

each BuildingBlock has

String shortName;
String fullName;
String blockID;
Array<Element> elements;

I tried looking into the source code, but the branches seem endless. I tried using debugging mode in NetBeans, but every third variable (setOfOrders, listOfBlocks, elements) just keeps expanding. This feels like trying to find which folders take space on your disk. With Explorer it takes forever, while some disk analyzers show a clear map of space usage.

So, what is the best way to analyze a bundled variable? Should I just expand it fully and search recognizable data structure? Is there command (I cannot ask for a tool, but I can ask for an IDE command, right?) to represent the structure of a variable? Should I rely on getters and setters?

Glu Glu
Answer Source

You have several options, each with own pros and cons.

You can implement toString method, but it defeats your purpose because to write it you need to know the structure of a variable.

You can use reflection, but this is a proprietary feature that might be gone in future releases.

Large projects typically have several huge global variables (like session, that might store everything relevant to this session) and a zillion of local variables. The structure of local variables is simple. Since there is only a small number of global variables you should ask team leader about their structure.