为什么Java不支持无符号整数? [英] Why doesn't Java support unsigned ints?

查看:1781
本文介绍了为什么Java不支持无符号整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Java不包含对无符号整数的支持?

Why doesn't Java include support for unsigned integers?

在我看来,这是一个奇怪的遗漏,因为他们允许编写一个不太可能在意外的大输入上产生溢出的代码。

It seems to me to be an odd omission, given that they allow one to write code that is less likely to produce overflows on unexpectedly large input.

此外,使用无符号整数可以是一种自我文档形式,因为它们表明unsigned int意图保留的值绝不应该是负数。

Furthermore, using unsigned integers can be a form of self-documentation, since they indicate that the value which the unsigned int was intended to hold is never supposed to be negative.

最后,在某些情况下,无符号整数对于某些操作(例如除法)可能更有效。

Lastly, in some cases, unsigned integers can be more efficient for certain operations, such as division.

包含这些内容的不利之处是什么?

What's the downside to including these?

推荐答案

这是来自采访Gosling及其他人,关于简单性:

This is from an interview with Gosling and others, about simplicity:


戈斯林:作为一名语言设计师,我现在并不像以前那样真实地认为自己,简单到底意味着什么,我可以期待J. Random Developer把规格放在脑海里。这个定义说,例如,Java不是 - 实际上很多这些语言都有很多极端情况,这些都是没有人真正理解的。测试任何C开发人员关于无符号的,很快你就会发现几乎没有C开发人员真正理解无符号算法是什么,无符号算术是什么。这样的事情让C变得复杂。我认为Java的语言部分非常简单。您必须查找的库。

Gosling: For me as a language designer, which I don't really count myself as these days, what "simple" really ended up meaning was could I expect J. Random Developer to hold the spec in his head. That definition says that, for instance, Java isn't -- and in fact a lot of these languages end up with a lot of corner cases, things that nobody really understands. Quiz any C developer about unsigned, and pretty soon you discover that almost no C developers actually understand what goes on with unsigned, what unsigned arithmetic is. Things like that made C complex. The language part of Java is, I think, pretty simple. The libraries you have to look up.

这篇关于为什么Java不支持无符号整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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