Florian Castelain :
I have several methods in a class that require a boolean to be set to true in order to execute correctly.
I could write the if
statement in each method, but it is not convenient if I or someone else wants to ad another method. I or he could forget about the check.
Is there a way in java to execute a method before each other methods (exactly like JUnit does with @BeforeEach
) in a class ?
Edit: Lots of very interesting techniques/answers/concepts proposed. I'll be in touch when I've understood them. Thanks.
Florian Castelain :
Considering my use case, it was a bit overkill to use AOP or other concepts. So I basically did a check in each functions.