Every Java developer sooner or later has the exact same problem. They wish they could see beyond their public API.
Because information hiding is brilliant but, when things don’t work, it is nice to have a way to bypass it.
xr (short for x-ray) gives you a laser beam to point against any Java object.
Suppose you are given an instance of this class:
public class Account {private int account_number;private String first_name;private String last_name;private Double balance;
...};
xr, lets you reveal its structure
**>>**xr(account);account_numberbalancefirst_namelast_name
and inspect its parts:
**>>**xr(account,"account_number");13342101**>>**xr(account,"first_name");John**>>**xr(account,"last_name");Smith**>>**xr(account,"balance");12,000
Flabbergasted ? I hope not.
xr is a ready-to-use Nashorn/JavaScript function which uses introspection to discover all the fields in an object and reach their values.
To use it, you need to run your Java program in an interactive environment. So, you have two alternatives:
For both options all you have to do is one call:
load('https://gist.github.com/lorenzoongithub/7273902ac628b2761f46de2d0c2a31cd');