Can an object be stored on the stack instead of the heap in Java?

Can an object be stored on the stack instead of on the heap?

I recently experienced this blog http://www.programmerinterview.com/index.php/data-structures/difference-between-stack-and-heap/

They suggest that objects can be stored in the heap This is puzzling

meseems,

>All objects in Java are stored on the heap Whether created by New keyword Bay uses class forName(). C. Use clone () Oh, my God Using the newinstance () method, that is, using the object deserialization > method, both threads and variables are stacks. > Class variables (static variables) are stored as part of the class object associated with the class Such objects can only be created by the JVM and stored in a persistent build

If I am wrong, please do me right

Now I wonder if objects can be stored on the stack in any form

thank you.

Solution

All class instances are stored in the heap

Here are some trusted sources: from the JVM specification: https://docs.oracle.com/javase/specs/jvms/se8/jvms8.pdf

From Java language specification: https://docs.oracle.com/javase/specs/jls/se8/jls8.pdf

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>