And my code in my VehicleDB (where I have declared the TreeMap) is:
And my print out to screen is as expected:
Test VehicleDB: Null values are allowed but should not be stored ================================================ NV52SSD reg is not Null so it will be allowed qp43SSX reg is not Null so it will be allowed ZZ43SSX reg is not Null so it will be allowed null: reg is Null so it will NOT be allowed
My question is, is this the best way to do it?
Thanking you in advance.
Joined: Dec 06, 2001
I find the following line of code a little suspicious:
I think you have a problem with understanding what null is. When the documentation says that null is (or is not) allowed, it is referring to a null reference. Even if you were to use a Collection that disallowed null values, the String "null" would still be allowed because this is NOT a null value; it's a String with the characters n-u-l-l.
So my question is do you really mean the String "null" or do you mean to use a null reference instead? If you use the keyword null, the check in the store() method will be a little simpler. You would be able to change
This also means you will need to change the constructor call for the VehicleRecord object to use a null reference instead of the String "null".