他们在java中说“每件事都是一个对象”。真的吗? [英] They say in java "every thing is an object". Is that true?
本文介绍了他们在java中说“每件事都是一个对象”。真的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我输入
int a = 5;
a
一个对象?
有人可以向我解释一下java中的每个东西都是对象吗?
Can anyone explain to me how in java every thing is an object?
推荐答案
每个对象都是 java.lang.Object
注意:java.lang.Object没有超类。 ;)
Every object is a java.lang.Object
Note: java.lang.Object has no super class. ;)
然而,有很多东西不是对象。
However there are many things which are not Objects.
- 原语和参考。
- 字段(字段本身不是内容)
- 局部变量和参数。
- 泛型类(可能在Java 8中更改)
- 方法(将在Java 8中更改)
- 代码块(将在Java中更改) 8)
- primitives and references.
- fields (the fields themselves not the contents)
- local variables and parameters.
- generic classes (that may change in Java 8)
- methods (that will change in Java 8)
- blocks of code (that will change in Java 8)
将一段代码作为对象是最令人兴奋的Java 8中的功能。以下示例都将是Closures及其对象。
Having a block of code as an object is one of the most exciting features in Java 8. The following examples will all be Closures and therefor objects.
x => x + 1
(x) => x + 1
(int x) => x + 1
(int x, int y) => x + y
(x, y) => x + y
(x, y) => { System.out.printf("%d + %d = %d%n", x, y, x+y); }
() => { System.out.println("I am a Runnable"); }
例如。这里的代码块将作为 Runnable
Object
e.g. the block of code here will be passed as a Runnable
Object
new Thread(() => { System.out.println("I am a Runnable"); }).start();
http://mail.openjdk.java.net/pipermail/lambda-dev/2011-September/003936.html
这篇关于他们在java中说“每件事都是一个对象”。真的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文