Long term NaN

I have a case where I only need to pass non-null values ​​and not empty strings to the repository.

For strings, I kept the constant "NULL_VALUE", for Double and Float, I use NaN.

Similarly, there is a way to store some value for Long, Integer and Boolean

public static void main(String... args) {

    Float fVal = Float.NaN;
    System.out.println("Float NaN :" + fVal);

    Double dVal = Double.NaN;
    System.out.println("Double NaN :" + dVal);

//  Integer iVal = Integer.NaN;
//  System.out.println("Integer NaN :" + iVal);

//  Boolean boolVal = Boolean.NaB; // Not a boolean

}

      

I am afraid to keep 0 or a large slice (999999999 for int).

What's the best way?

+3


source to share


1 answer


if I understand your question correctly, you don't want to store the values null

in your database.

By default for objects like Float

, Boolean

etc., null

you will have to fall back to the default values ​​of the corresponding primitives, for example: 0.0f

for Float

, false

for Boolean

, etc.



Another approach would be to define your own default values. As you said, "NULL_VALUE"

it String

may not be that bad for, as there is no alternative.

0


source







All Articles