In btrace, How can I compare and check the value of an Enum object?

131 Views Asked by At

I have the callback set up correctly in btrace. My argument list contains a custom Enum object. I want to print something if the Enum object equals to a specific value. I am OK with either comparing the Enum object directly, or comparing the string representation of that Enum object with a constant string.

However, the str() function doesn't return me the string representation of this Enum object. It returs the path$class@hash.

How can I compare Enum object in btrace?

Thanks! Erben

1

There are 1 best solutions below

0
On

Found the answer. The string representation of an Enum is stored in the "name" field of this Enum object. So use reflection to get the value of that "name" field from the object like this:

private static Field enumNameField = field("java.lang.Enum", "name");
String stringRepresentation = (String) get(enumNameField, enumObject);