akula barakula
akula barakula

Reputation: 21

Determine variable type

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.

  1. update: added more details
  2. update: clarified question

Upvotes: 1

Views: 259

Answers (2)

akula barakula
akula barakula

Reputation: 21

it is possible using StaticTypeCheckingVisitor. In order to see more details, please, follow this link

Upvotes: 1

Festus Tamakloe
Festus Tamakloe

Reputation: 11310

In java you can use instanceof to determine a type of an object

Upvotes: 0

Related Questions