0
votes

I want to check for valid IDs. Should I check for id > 0 || id < -1 or just id > 0?

The documentation just states that 0 and -1 are reserved and that the next ID will be higher then the highest present ID, with an example starting at 1. Is it just an example or can we rely on that?

1
It sounds like the IDs are auto-generated. Why are you trying to validate them? - Tyler
e.g. to prevent Database.boxFor(clazz).get(id) from crashing my app. - cybergen

1 Answers

1
votes

A valid ID is id > 0 || id < -1 or id != 0 && id != -1.

The first IDs are always 1, 2, 3, ...

If you have IDs 1,2,3,4,5 and delete 4 and 5, new IDs may or may not reuse 4 and 5. You should not rely on that behavior.