2

I have an app in grails which uses list contained in a map. I am using the list for simple string comparison in my code (value[0]=="something" for example). the println showed the value[0] to be "something" but the test always failed. On further checking the class for value[0] [through value[0].getClass() ], I found the class of type [C. Anybody has any clue on this. The list is stored in a map and I am doing a map.each to get to the list (if that makes a difference). Here is my code and println output in my console.

code

println "it.value[0] = " + it.value[0]
println "it.value[1] = " + it.value[1]
println "it.value[2] = " + it.value[2]

println "it.value[0] class = "+ it.value[0].getClass()
println "it.value[1] class = "+ it.value[1].getClass()
println "it.value[2] class = "+ it.value[2].getClass()

output

it.value[0] = abc
it.value[1] = def
it.value[2] = ghi

it.value[0] class = class [C
it.value[1] class = class [C
it.value[2] class = class [C
4

1 回答 1

5

[C是原始字符数组 ( char[]) 的 Java 字段描述符。当您检查数组类型的类名时会显示这些。

assert ("foo" as char[]).getClass().toString() == 'class [C'

它们如何构建的规则位于字段描述符的JVM 规范部分

于 2012-08-10T20:44:31.630 回答