Community
Participate
Working Groups
I would like to have an option in equals generation to consider empty Lists or Hashs the same thing as null lists/hashs. Equals example (for a "tags" List) today: if (tags == null) { if (other.tags != null) { return false; } } else if (!tags.equals(other.tags)) { return false; } Equals example (for a "tags" List) with consider [empty list] == [null list] option enabled: if ( (other.tags == null || other.tags.size() == 0) && (tags == null || tags.size() == 0)) { return true; } else if (tags == null || tags.size() == 0) { if (other.tags != null || other.tags.size() > 0) { return false; } } else if (!tags.equals(other.tags)) { return false; } Thank you.
I personally am not sure, that's a coding style that JDT wants to actively support. Wouldn't consistently using empty lists instead of null make for much simpler and safer code?
You are right, but these objects come from ReST services and sometimes they are null or empty. From the business point of view, it is the same thing; that´s why I ask for this feature.