为什么java没有字节类型后缀? [英] Why does java have no byte type suffix?

查看:163
本文介绍了为什么java没有字节类型后缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此java的文字后缀为long类型:(123L),双类型后缀(43.21D),浮点后缀(1.234F)。那么......为什么没有字节类型后缀?例如,在编写一些测试代码时,必须在将它们用作函数参数时强制转换所有字节。

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

很明显,使用B或b不会起作用,因为它会与能够以十六进制或八进制(一种关键语言特征)指定字节。但是其他一些字母,比如Z z?或Y y(对于bYte)?

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

推荐答案

这并没有真正回答为什么这个问题,但对于它的价值,那里是2009年3月提出的一个提案,其中Y字节后缀为字节,S为短裤:字节/短后缀提案

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

这篇关于为什么java没有字节类型后缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆