views:

79

answers:

1

So java has a long type suffix for literals: (123L), a double type suffix (43.21D), a floating point suffix (1.234F). So ... why no byte type suffix? For example, when writing some testing code you MUST cast all your bytes when they are used as function parameters.

ByteBuffer b = ByteBuffer.allocate(100);
b.put((byte)3);   // super annoying
b.put(3b);        // if only

It is clear that using B or b would not work since it would conflict with the ability to specify a byte in hexadecimal or octal (a critical language feature). But some other letter, like Z z? or Y y (for bYte)?

+3  A: 

This does not really answer the question of why, but for what it's worth, there was a proposal put forward in March of 2009 for just this with the Y byte suffix for bytes and S for shorts: Byte/short suffix proposal

Michael Goldshteyn
Interesting proposal, it also addresses the unsigned problems associated with bytes.
Justin