Backend Development 5 min read

Why Using isXXX Naming for Boolean Fields in Java Is Discouraged

The article explains Java naming conventions for primitive boolean and Boolean types, shows examples of getters and setters, discusses JavaBeans rules and RPC serialization issues, and recommends using wrapper types for POJOs while keeping primitives for local variables.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Why Using isXXX Naming for Boolean Fields in Java Is Discouraged

In everyday Java development, developers often encounter the primitive boolean type and its wrapper class Boolean , and wonder whether to name fields with the isXXX pattern.

The article presents several code examples:

private String isHot;
public String getIsHot() { return isHot; }
private boolean isHot;
public boolean isHot() { return isHot; }
private Boolean isHot;
public Boolean getHot() { return isHot; }
private boolean hot;
public boolean isHot() { return hot; }
private Boolean hot;
public Boolean getHot() { return hot; }

According to Alibaba's Java development manual, both boolean and Boolean fields must not use the isXXX naming style.

For non‑boolean parameters, getters and setters should start with get and set .

For boolean parameters, the setter starts with set , but the getter should start with is .

Wrapper classes always generate getters and setters named getXXX() and setXXX() .

The JavaBeans specification defines that primitive properties use getXXX() / setXXX() , while boolean primitives use isXXX() / setXXX() . Wrapper types, however, always use getXXX() / setXXX() .

Using isSuccess() for a boolean wrapper can cause RPC frameworks to misinterpret the property name, leading to serialization errors and exceptions.

Summary

1. Naming boolean properties with is can trigger RPC serialization problems.

2. If an IDE generates an isSuccess() method for a wrapper, rename it to getSuccess() to ensure proper property access; both methods can coexist, but getSuccess() should be used for retrieval.

Choosing Primitive vs. Wrapper Types in Practice

Consider a profit‑calculation system: using a primitive double may return 0.0 on RPC failure, masking errors, whereas a Double wrapper returns null , making the failure evident.

Alibaba's Java development handbook enforces using wrapper types for POJO fields and primitives for local variables.

JavaRPCBooleanJavaBeansNaming ConventionWrapper Class
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.