Every object is a java.lang.Object
(NOTE:java.lang.Object
has no super class. ;) )
However, there are many things which are not Objects.
- 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)
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 therefore 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"); }
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…