Why is there always Empty while I use! IsEmpty 99% of the time

This question has eclipsed me quite a long time. During programming, the question regularly arises whether there is something in the object or not. For this reason, the isEmpty method was invented. Great, but in practice we use it like !isEmpty almost all the time.

As a result, notEmpty will be a much more valuable addition to a language like Java. The question is, why do language developers not think about this before defining an API? At least give an analog to isEmpty

EDIT: I meant that it should be notEmpty as well as isEmpty . Depending on the domain, both of them can be used, but in most cases when the user interface is not involved, I think that notEmpty is better applied.

EDIT2: To close the discussion, here is an example:

 !metadata.isEmpty() == metadata.notEmpty() 

I would prefer that we have the right side of the equation.

+7
java
source share
3 answers

isEmpty follows the naming of other syntactically positive isXXX methods, such as isVisible and isEnabled

+6
source share

I think this follows the convention to use is[Something]() for booleans instead of get[Something]() .

Also, using !notEmpty() can be a bit confusing!

+4
source share

My opinion, this is more logical, because, like == and != . Logically. Better to have isEmpty and !isEmpty , it's easy to understand.

+2
source share

All Articles