Re: Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-05 Thread Martin Grigorov
Hi, You can file a feature request to Java developers. A compiler flag can forbid this behavior. On Sun, Aug 4, 2019, 14:05 mscoon wrote: > Thomas, > > Thanks for the info. > > The domain objects not being serializable is certainly a valid option. > > To return to my original point, even this

Re: Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-04 Thread mscoon
Thomas, Thanks for the info. The domain objects not being serializable is certainly a valid option. To return to my original point, even this does not completely solve the issue with unintended serialization. Sure, you are going to get a serialization exception but this is a runtime error

Re: Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-04 Thread Thomas Heigl
> > Would you mind to elaborate on this a bit? What do you do in your forms? > How do you handle state there? Do you use view models that are > serializable? Do you keep state in local variables and propagate it to the > domain object in every request after it is reloaded? Sure. We use

Re: Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-04 Thread mscoon
Hi, If you don't mind me following up on your comment... > Personally, I rarely encounter serialization issues. None of our domain > objects implement Serializable. They can only be used with > LoadableDetachableModels that only store the identifier. > >> >> Would you mind to elaborate on this

Re: Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-04 Thread Thomas Heigl
The IntelliJ inspection has configuration options. If you enable only the last option "Report variables which are implicitly final", it might help with your problem: [image: image.png] Personally, I rarely encounter serialization issues. None of our domain objects implement Serializable. They

Re: Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-04 Thread mscoon
Thank you for your answer Thomas. "Local variable or parameter can be final" inspection actually does something different. It will warn that a parameter can be made final when its value does not change, even if it not used in an anonymous class. This will result in programmers declaring all

Re: Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-04 Thread Thomas Heigl
Hi Marios, I don't think there is a way to disable this behaviour but you have other options: - If you use IntelliJ, you can configure the "Local variable or parameter can be final" inspection to raise an error instead of a warning (for variables that are implicitly final) - Checkstyle or

Java 8 access to effectively final variables/method parameters from anonymous classes

2019-08-04 Thread mscoon
Hi all, Java 8 introduced the ability to access effectively final variables/method parameters from anonymous classes without having to add explicitly the "final" keyword. This has resulted in a lot of cases where the programmer does not notice that they are referencing a model object from an