问题描述
Java中的类,对象和实例是什么?
Java(和任何其他编程语言)根据类型和值建模。在理论层面,值是对于某些信息量的表示,类型是一组值。当我们说值X 是类型Y的实例时,我们只是说X是Y类型的值的集合的成员。
$ b $
这是Java编程语言的类型系统支持两种类型,原始类型和引用类型。引用类型进一步分为类和数组类型。 Java对象(根据JLS)是引用类型的实例;即数组或类的实例。
这是类型理论视图。
实际上,大多数Java开发人员将instance和object这两个词视为同义词。 (包括我然后我试图快速解释一些东西。)大多数开发人员使用值而不是实例来引用一个原始类型的实例。
What is a class, an object and an instance in Java?
Java (and any other programming language) is modelled in terms of types and values. At the theoretical level, a value is a representation for some quantum of information, and a type is a set of values. When we say value X is an instance of type Y, we are simply saying that X is a member of the set of values that is the type Y.
So that's what the term instance really means: it describes a relationship not a thing.
The type system of the Java programming language supports two kinds of types, primitive types and reference types. The reference types are further divided into the Classes and array types. A Java Object is (according to the JLS) an instance of a reference type; i.e. either an array or an instance of a Class.
That's the type theoretic view.
In practice, most Java developers treat the words "instance" and "object" as synonyms. (And that includes me then I'm trying to explain something quickly.) And most developers use "value" rather than "instance" to refer to an instance of a primitive type.
这篇关于类,对象和实例之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!