Java – use enum vs Boolean?

This may seem generic at first, but in fact, I'm actually making the decision I need to use

My ongoing work involves job applications that need to be marked as active or inactive at some time When you submit an application, it defaults to active For some reason, it may be set inactive later It can only be one of them and is never null (if anything is changed in this way)

I'm using java hibernate PostgreSQL in case it's different My first instinct is to use Boolean values as my solution to make it really a flag, but I have suggested using enumerations or ints as more states than flags

I have solved the problem of using all the above solutions, and they seem to be somewhat transparent to each other

Is there a better way to deal with this situation?

Solution

It depends entirely on your requirements / specifications If you only want to record the state as active or inactive, the best way is to use Boolean values

But if you will have such a state in the future,

>Active > inactive > pause > block

Enumeration is perfect In your case, for now, Boolean values are sufficient Don't try too much too early, you will lose your design and develop your system

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>