Java 的原语是一等公民吗? [英] Are Java's primitives first class citizens?

查看:73
本文介绍了Java 的原语是一等公民吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计算机程序的结构和解释 Gerald Jay Sussman 和 Harry Abelson 对一等公民的描述是:

In Structure and Interpretation of Computer Programs by Gerald Jay Sussman and Harry Abelson first-class citizens are described with:

  • 它们可能由变量命名.
  • 它们可以作为参数传递给过程.
  • 它们可能作为程序的结果返回.
  • 它们可能包含在数据结构中.

对我来说,这意味着原始数据类型是一等公民.然而,有一些问题和答案我看到了将原语视为非一等公民的答案.

For me it means that primitive data type is the first-class citizen. However is some questions and answers I see answer considering primitives as non first-class citizens.

问题是:Java 的原语是一等公民吗?

The question is: are Java's primitives first class citizen?

推荐答案

根据您问题中的定义,是的,它们是.其他人使用的定义可能与您问题中的定义不同.如果你使用不同的定义,那么他们可能不符合它.例如,在您链接的答案中,问题暗示的定义将涉及它们从Object,当然它们不是,所以根据那个定义,它们不是.

By the definition in your question, yes, they are. The definition being used by others may not be the same as the definition in your question. If you use a different definition, then they may not meet it. For instance, in the answer you linked, the definition implied by the question would involve their being derived from Object, which of course they aren't, and so by that definition, they aren't.

这一切都归结为您所说的一等公民".

It all comes down to what you mean by "first-class citizen."

这篇关于Java 的原语是一等公民吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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