Fun exercise - someone who knows Scala can probably do better - of course you could hide all this away in a library and make it really easy if you wanted: val m = Map(1->"a",2->"b",3->"c")val field = m(1).getClass.getDeclaredField("value")field.setAccessible(true)val mods = field.getClass.getDeclaredField("modifiers")mods.setAccessible(true)mods.setInt(field, field.getModifiers & ~java.lang.reflect.Modifier.FINAL)field.set(m(1), field.get(m(2)))println(m)// => Map(1 -> b, 2 -> b, 3 -> c)
On Fri, Nov 25, 2011 at 10:50 AM, Kevin Wright <kev.lee.wri...@gmail.com> wrote: > C'mon! > 1. Open a fresh scala REPL. No imports, no other lines of code, just a clean > standard REPL > 2. val m = Map(1->"a",2->"b",3->"c") > 3. Your challenge, should you accept it, is to manipulate m in such a way as > to change its value > 3a. and no, creating a new m doesn't count > > 2011/11/25 Cédric Beust ♔ <ced...@beust.com> >> >> On Thu, Nov 24, 2011 at 3:42 PM, Kevin Wright <kev.lee.wri...@gmail.com> >> wrote: >>> >>> it embraces the same ideals of immutability that he once championed >> >> We already went through this, Scala "the language" does very little to >> enforce immutability. Hardly more than Java. >> -- >> Cédric > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to javaposse@googlegroups.com. > To unsubscribe from this group, send email to > javaposse+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to javaposse@googlegroups.com. To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.