2

For example, GWT 2.4.0 still complains "Field 'private final...' will not be serialized because it is final".

The easiest way is to add a setter (or any dummy-method, making the assignment of local variable, which we want to prevent becoming final (if, for instance, setter already have and it does not assign)).

2
  • Do you use some kind of code generator ? Because I don't understand the question... Personaly I prevent the "final" modificator by not writing it in the first place...
    – Vinze
    Oct 20, 2011 at 9:55
  • @Stephan GWT does not use java serialization but a custom java<->javascript one... not sure overriding readObject will do anything to this specific problem
    – Vinze
    Oct 20, 2011 at 9:59

1 Answer 1

4

You can find the settings under Window > Preferences > Java > Editor > Save Actions > Additional Actions > Configure... > Code Style

And regarding your comment:

I want to disable adding the modifier to a single line, not the entire project.

Eclipse doesn't really have a clean way to do this. What you could do is just open the file with the Eclipse Text Editor instead of the Java Editor and delete the final keyword manually, but I'm afraid there's not much you can do beyond that.

Or create an unused method that re-assigns the field, but that's kind of hacky as well.

6
  • I want to disable adding the modifier to a single line, not the entire project.
    – Green
    Oct 20, 2011 at 10:30
  • 1
    Thank you, I've used this hack:)
    – Green
    Oct 20, 2011 at 11:43
  • as i can't answer to the right place i will comment your comment on my comment here... i wasn't saying final shouldn't be used, just that when i don't want something to be 'final' i don't add the modificator (apparently the user automated it, the part of the question i didn't understand). And i do most of the time what the answers in the discussion you pointed state (always on immutable fields, rarely on parameters i admit - unlike when i worked with c). But i know it's hard to change habits to adapt a new tech (and GWT when i learned it wasnt always friendly with old java habits)
    – Vinze
    Oct 20, 2011 at 14:08
  • @Vinze I have used the automated way for years, and it makes things so much easier :-) Oct 20, 2011 at 14:50
  • i can't agree more... but "in theory there's no difference between theory and practice, but in practice there is"... and I'm now used to forget all my habits from a project to another (i now must do java 1.3 compatible code which was already deprecated when i learned java and i have neither delorean neither tardis...) so i never automate anything, it's too frustrating when you can't use it anymore (ok i keep autocompletion) :( maybe I should instead of overcomplicating my job :)
    – Vinze
    Oct 20, 2011 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.