some methods. This methods use some FLAGS that are declared as private booleans as false attributes. My application is a web one, so it's executing on a browser and this class executes its methods when the user clicks on a button and flags are false. The problem is the following: first time code executes well, flags are put to true (correct behaviour) after conditions for execution are met. The following times the user clicks on the button the code is not executing because the flags are true already. Is there a way to "clean2 this flags when the method of this class is called from the outside? I cannot know which class is executing because there are plenty and, depending on some data, class A,b,C or D will execute via reflection. So I'm not sure if I can call a constructor or smth like that. Thank you so much!
No sure whether I understood it correctly. But it seems that you are looking for ! negation logical operator: var flagState = flagHolder.getFlag(); flagHolder.setFlag( ! flagState);
I do have some questions on this: 1. Why can't you simply set the flags to false from outside? 2. If that is not allowed, is it the case where the class which you are trying to execute again on user click is supposed to execute only once? If so then understand why it was designed that way. 3. If you realise it was designed that way then there's something that you are doing wrong.
1. Because the class executing as well as its method its obtained via java reflection, dynamic. I guess i could try to call a clean method or a constructor, but i would need to hard code the name of the method i guess? 2. No, it can be executed many times. It generates some information for the user on click event.
Thank you for the answer! I think i did not explain myself well enough haha
1. I am sorry, I have limited experience with reflections. 2. If that is the case then why are those flags limiting the methods from being executed multiple time?
1. No problem man :) 2. Its a bit complex to explain here. But the thing is the first time flags are set to true, then the second time they are already true. During the execution of this class, some methods are called more than once but some parts of them must be executed only one time, thats why there are flags.
Let me ask this. If there was no reflection involved, would the problem be different? Still I can't understand what is the problem. Based on your description void yourMethod() { // code that will be always executed if (!wasBlock1executed) { // block1 which should be executed only once // ... wasBlock1Executed = true; } if (block2NumExec <= 3) { // block2 should be executed no more than 3 times // ... block2NumExec++; } } Anyway, we're playing guessing game here. You won't get any real help without showing exact code which you're having problem with
Thank you for your time. I will try to pass by tomorrow and show some code!
Обсуждают сегодня