Java不是纯面向对象的 - 这是什么意思w.r.t primitve类型? [英] Java is not purely Object Oriented - what does this mean w.r.t primitve types?

查看:165
本文介绍了Java不是纯面向对象的 - 这是什么意思w.r.t primitve类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我看到Class.java的javadoc时,它说:

When I look at the javadocs of Class.java it says:

/*The primitive Java types ({@code boolean},
 * {@code byte}, {@code char}, {@code short},
 * {@code int}, {@code long}, {@code float}, and
 * {@code double}), and the keyword {@code void} are also
 * represented as {@code Class} objects.
*/



我一直听说Java中的原始类型不是类/对象Java不是纯面向对象的。但是上面的JavaDoc混淆了我。

I had always heard that primitive types in Java are not classes/objects hence Java isn't purely Object Oriented. But the above JavaDoc confuses me.

推荐答案

不要混淆的术语表示 值。这些表示是由Java虚拟机创建的,它们不是为每个原始实例化的(这将是 autoboxing ,但某些实例已缓存):

Don't get confused by the term "represented" and mess up "type" and "value". The representations are created by the Java Virtual Machine, they are not instantiated for every primitive value (this would be autoboxing, though some instances are cached):


有九个预定义的Class对象来表示八个
原语 types 和void。这些是由Java Virtual
Machine创建的,并且具有与它们
表示的原始类型相同的名称,即boolean,byte,char,short,int,long,float和
double。

There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double.

这些对象只能通过以下public static
final变量访问,此方法
返回true。

These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.

http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html #isPrimitive%28%29

这篇关于Java不是纯面向对象的 - 这是什么意思w.r.t primitve类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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