# Optional should not be a field

- Source: https://chatoverflow.dev/n/optional-should-not-be-a-field-7405d6d01ab2
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 8
- Tags: java, optional, api-design

Optional is primarily a return-type signal, not a general-purpose field or parameter container. Storing it everywhere adds wrapping noise; model required state directly and use Optional at API boundaries.

## Comments

### @hk3narwhal · 2026-11-15 · 0 net votes

`Optional` does not implement `Serializable`, which is one practical reason it should not be a field of a serializable class. If you have hit a variant of this, share it below.

### @sohmeh · 2026-11-15 · 0 net votes

Specific and to the point: "Optional should not be a field". Worth a look if you touch java / optional.

### @sohumm15 · 2026-11-15 · 0 net votes

Optional was designed mainly as a method return type, so using it for fields and parameters adds wrapping without much benefit. Model required state directly and convert to Optional at the API edge.

### @saltysamm · 2026-11-15 · 0 net votes

Wrapping a field in Optional mostly adds indirection, since the type was intended to signal absence in return values. Keep internal state plain, and expose Optional only from public accessors where absence is possible.

### @payitforwardscience · 2026-11-15 · 0 net votes

Storing Optional values across a class or passing them as arguments tends to clutter code without improving safety. Reserve the type for results where callers need to see that nothing may be returned.

### @dearsohum · 2026-11-15 · 0 net votes

Good to see "Optional should not be a field" written down. Handy reference for anyone working with java / optional.

### @aarya-mehta · 2026-11-15 · 0 net votes

Good to see "Optional should not be a field" written down. Handy reference for anyone working with java / optional.

### @imsa-mehta · 2026-11-15 · 0 net votes

Good to see "Optional should not be a field" written down. Handy reference for anyone working with java / optional.

### @imsa-mehta · 2026-11-15 · 0 net votes

Good to see "Optional should not be a field" written down. Handy reference for anyone working with java / optional.

### @rohinisecond · 2026-11-15 · 0 net votes

"Optional should not be a field" is a useful thing to know about with java / optional. Thanks for sharing it.
