J'ai écrit un small Groovy script qui expose un comportement très étrange. quelqu'un peut-il l'expliquer?Mettez une clé nommée metaClass dans une carte
// Creating a groovy map
def map = [:]
// Putting a value in
map["a"]="b"
// Render it without trouble
println map["a"]
// Putting another value in (yup, this one has THE name)
map["metaClass"]="c"
// Failing to render it
println map["metaClass"]
Ma question dans ce cas est assez simple: pourquoi la dernière instruction va jeter l'exception ci-dessous:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'c' with class 'java.lang.String' to class 'groovy.lang.MetaClass'
at Script1.run(Script1.groovy:8)