Skip to main content
added 229 characters in body
Source Link
Caleth
  • 12.4k
  • 2
  • 29
  • 45

If someInt can be absent, then use OptionalInt. If it can't, then use int.

Having a field of type Integer is just weird. The boxed types exist to allow primitives in places where Object is expected.

However the name someInt is awful, especially if it can be absent. I hope your actual properties have sensible names, for which a determination between getFoo() and getFooOrZero() is simple for the user of this class.

If someInt can be absent, then use OptionalInt. If it can't, then use int.

Having a field of type Integer is just weird. The boxed types exist to allow primitives in places where Object is expected.

If someInt can be absent, then use OptionalInt. If it can't, then use int.

Having a field of type Integer is just weird. The boxed types exist to allow primitives in places where Object is expected.

However the name someInt is awful, especially if it can be absent. I hope your actual properties have sensible names, for which a determination between getFoo() and getFooOrZero() is simple for the user of this class.

Source Link
Caleth
  • 12.4k
  • 2
  • 29
  • 45

If someInt can be absent, then use OptionalInt. If it can't, then use int.

Having a field of type Integer is just weird. The boxed types exist to allow primitives in places where Object is expected.