I was reading about how you can "trick" a program into letting an anonymous inner class modify the value of a local variable. Since anonymous inner classes can only deal with variables declared final, the suggestion is creating an array, declaring the array final, and then using the anonymous class to modify the values within the array. Since using final on an array means that you can't assign any other array to that variable, but can still modify the elements within it, I was wondering if there is a way to declare the elements within the array as final? Would you ever really want to do this in the first place? I tried but obviously it is just sticking a copy of the value. Thanks Jason
[This message has been edited by jason adam (edited November 09, 2001).]
You can't do it with an array, but you can use a List and wrap it inside a Collections.unmodifiableList(). The trick you mentioned is not something I'd use in Real Life[tm], by the way. - Peter
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Ya, I don't think I've ever come across anything that would require it, it was just mentioned as a work around, which got me curious about making an array of final elements. Thanks for the info Jason