Create a string with the result of an expression and the expression that originated the value. Is it
Posted
by Oscar Reyes
on Stack Overflow
See other posts from Stack Overflow
or by Oscar Reyes
Published on 2010-04-29T20:04:55Z
Indexed on
2010/04/29
20:07 UTC
Read the original article
Hit count: 387
Like
String r = SomeThing.toExecString("new Object().toString()");
And when executed the value of r
would be:
"new Object().toString() = java.lang.Object@c5e3974"
Is this even possible at all? Would it need a bunch of reflection? A built in compiler maybe?
AFAIK, this is not possible with regular Java.
The closest thing I could get is IDE support like in IDEA with the "macro" soutv+tab
that prints:
Hit tab
and type the expression
The IDE types the rest for you.
But that's quite another completely thing.
© Stack Overflow or respective owner