sialcasa / mvvmFX

an Application Framework for implementing the MVVM Pattern with JavaFX
Apache License 2.0
484 stars 105 forks source link

Prevent double initialization of ViewModels which have both naming-convention and @Initialize annotated init method #604

Open manuel-mauky opened 4 years ago

manuel-mauky commented 4 years ago

If a ViewModel has a single method with the signature of public void initialize() which is also annotated with @Initialize then this method will be invoked two times by the ViewLoader.

public class MyViewModel implements ViewModel {

    @Initialize
    public void initialize() {
        System.out.println("Will be invoked twice");
    }
}

The reason for this is that mvvmFX supports the naming convention of standard JavaFX and has also an annotation for initialization.

However, this is can lead to errors because double initialization is most likely a bug. To fix this we should invoke the initialize method only once.