0

I'm working on a project that uses a method that checks if there are no variables inside the Set. Using isEmpty() isn't recommended as it computes the set of all variables, which can be an undesired “overhead”. I have to write something that does not compute the set of all variables.

public boolean isVarFree(){
    getVar().isEmpty() //not recommended
}
reiko1879
  • 37
  • 4
  • I'm surprised to hear that it works this way, as that seems unnecessary. But the first thing to do is use a profiler to see where your code needs optimizing. – Don Branson Jan 10 '20 at 19:39
  • Also, I'm not sure what you mean by "it computes the set of all variables". Most implementations I'm aware of keep track of a `size` variable, and the implementation of `isEmpty()` is `return size == 0;` – azurefrog Jan 10 '20 at 19:39

0 Answers0