How to present the nullable primitive type int in Java?

后端 未结 13 997
灰色年华
灰色年华 2020-12-03 13:29

I am designing an entity class which has a field named \"documentYear\", which might have unsigned integer values such as 1999, 2006, etc. Meanwhile, this field might also b

13条回答
  •  [愿得一人]
    2020-12-03 13:44

    You're going to have to either ditch the primitive type or use some arbitrary int value as your "invalid year".

    A negative value is actually a good choice since there is little chance of having a valid year that would cause an integer overflow and there is no valid negative year.

提交回复
热议问题