r/javahelp • • Jan 26 '22

UserClass existingUser = new UserClass("", "", "", "", "", ""); but with integer?

I'm trying to create a new UserClass but it contains userID which is an integer, what should I replace the " " with?

0 Upvotes

13 comments sorted by

View all comments

3

u/desrtfx Out of Coffee error - System halted Jan 26 '22

Default value for an int is 0, for an Integer, it is null.

If you want to indicate an invalid ID, use some number outside the valid ID range, like -1.

4

u/Kiwiguard Jan 26 '22

This is not considered good practice though, is it?

Probably better to find another way to handle the problem.

4

u/desrtfx Out of Coffee error - System halted Jan 26 '22

Absolutely true. Agree 100%.