I have zero encounter with Scala. I'm returned an scala object by a library(kafka) of the following type:
kafka.coordinator.GroupMetadataManager$$anon$2@2b9ee60f
I tried to pass this to Scala to get some meaningful information. i.e. to access the data members.
package metricsReporter;
import kafka.coordinator.GroupMetadataManager;
class processMetrics {
def hello() { println("Hello (class)") } // [1]
def printGM(gmObject: AnyRef ) {
println(gmObject)
}
}
I'm calling the above function from java like this
new processMetrics().printGM(metric);
This function is also ouputing the same text. I also get other objects like anon$2, anon$3 (which should have data about different kafka partitions) of the same type.
You don't need to do it in scala. What you've written in your question is equivalent to System.out.prinln(metric)
. What the other answer suggests you to do is similar to:
for (Field field: metric.getClass().getDeclaredFields()) {
field.setAccessible(true);
System.out.println(field.getName() + ": " + field.get(metric));
}
There is nothing magical going on here.
It's another issue, that neither of these approaches seem to make any sense. You shouldn't need to use reflection to access data returned to you by public APIs. It seems that there definitely should be a better way to do what you are trying to do here ... if only we knew what the latter really is ... Edit: Syntax