Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

oop - They say in java "every thing is an object". Is that true?

When I type

int a = 5;

Is a an object ?

Can anyone explain to me how in java every thing is an object?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...