Reputation: 21
How can I determine type of Groovy
variable using Java
?
For example we have the next Groovy
code:
a = new Integer(4);
b = a + 1;
a = "b = " + b;
How can we programatically analyze it and determine that type of a
variable at b = a + 1;
line is java.lang.Integer
?
As a
is dynamic variable we can't get its type from Groovy AST
, because AST
doesn't contain such info.
Upvotes: 1
Views: 259
Reputation: 21
it is possible using StaticTypeCheckingVisitor
. In order to see more details, please, follow this link
Upvotes: 1
Reputation: 11310
In java you can use instanceof
to determine a type of an object
Upvotes: 0