I have following code. I am getting "Avoid using Literals in Conditional Statements." warning in PMD on line number 5.
List<Object> listObj = getData();
if (listObj.isEmpty()) {
throw new NoEntity("No entity found for given Device.");
}
if (listObj.size() > 1) {
throw new MultiEntity(
"Multiple entity record found for given Device.");
}
I prefer not to put global static final int variable having value as 1 and use it in if condition. Any other solution for this ?
if (listObj.iterator().next().hasNext())
but that would get -99 when posted as answer. Philosophical:if (listObj.size() != Byte.BYTES) { throw new ... + listObj.size()
– Stolon