json4s JValue scala classTag works wrong

80 Views Asked by At

In my code, I use classTag[JValue] want to get org.json4s.JsonAST.JValue , but actually it returns org.json4s.JsonAST$JValue, it is strange ! why there is the $? I am new guy use scala ,could someone answer me ? thanks a lot

1

There are 1 best solutions below

3
On BEST ANSWER

The name you use to refer to a class/method/etc. in your code and the name it has in bytecode produced by the compiler doesn't have to be the same. Scala compiler needs to be more of this name-mangling than the Java compiler, but this specific case is same for both.

The reason is that inner classes don't really exist on JVM: they are normal classes which have an additional field containing the outer instance. The JVM name of the class looks like <outer_class>$<inner_class>.

In Scala and Java, $ in a name generally indicates it's mangled in some way (though it is a legal character for programmers to use as well).