1

Does a more natural way to represent those numbers without the use of casting exist in Java?

float tolerance = (float) 8.0e-7;
byte[] data = new byte[]{(byte) 0xFF , (byte) 0x15};

Not using casting on those instances just doesn't work at all, and it just looks weird when you are defining constants of a primitive type and you have to use casting to represent it (it is like you are saying that Java doesn't support those data types naturally which is ridiculous).

I understand that for the float number you can represent it like this:

float tolerance = 0.0000008f;

but it is just almost unreadable in this form.

1 Answers1

2

For float values, you can simply express within the literal that you want a float, and not a double (which requires the cast):

float tolerance =  8.0e-7F;

There is no literal for bytes though (see here).

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248