Why does java have no byte type suffix? [closed]

大憨熊 提交于 2019-12-09 15:18:44

问题


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)?


回答1:


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



来源:https://stackoverflow.com/questions/4059306/why-does-java-have-no-byte-type-suffix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!