For bonus points, use JNI and do it in C/C++ Seriously though, all bets are off in the face of reflection. It can cut right through anything marked as final in bytecode, and no immutability guarantees made by *any* JVM language can be relied upon when reflection is being used to subvert the system.
On 25 November 2011 02:02, Paul King <[email protected]> wrote: > Sorry about the formatting glitches, trying again: > > 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) > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > -- Kevin Wright mail: [email protected] gtalk / msn : [email protected] quora: http://www.quora.com/Kevin-Wright google+: http://gplus.to/thecoda <[email protected]> twitter: @thecoda vibe / skype: kev.lee.wright steam: kev_lee_wright "My point today is that, if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger" ~ Dijkstra -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
