Are Java's primitives first class citizens?

2019-09-17 06:39发布

问题:

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

  • They may be named by variables.
  • They may be passed as arguments to procedures.
  • They may be returned as the results of procedures.
  • They may be included in data structures.

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.

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

回答1:

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 oop