找到你要的答案

Q:please explain for me what we can do instead of pointer in java and how work? [closed]

Q:请给我解释一下我们能做些什么,而不是指针在java和如何工作?[关闭]

I want to write link list in java but I don't know how can I save the last address. so please explain for me how can i do that? Or please share a link to read basic of this work in java.

我想在java写的链表,但我不知道我怎么能保存地址。所以请为我解释我该怎么做?请分享链接在java读取这个工作的基本。

answer1: 回答1:

Java has primitives and references. This is all you need in Java. If you want to refer to an object, you use a reference. This is like a pointers except you

  • don't have pointer arithmetic which means the JVM can arrange the objects how it likes.
  • don't use explicit pointer referencing.
  • don't see the underlying address. This means that a 64-bit JVM typically uses 32-bit references up to 64 GB of memory. Something you couldn't do if you used pointer arithmetic.

how can I save the last address.

You use assignment like this.

Double d = new Double(1.0);

This saves the reference to the object new Double(1.0) into the variable d.

please share a link to read basic of this work in java.

A reference is a pointer you can't manipulate, only copy and dereference. There is nothing more to it.

Why does Java do it this way?

To keep things as simple as possible for the developer. They try to give you the minimum set of functionality to make the code easier to maintain. There is still plenty of ways to solve the same problem but it avoid most of the complex functionality. (You might not agree with the range of choices, like why "signed byte" instead of "unsigned byte", but they I believe that was the intent)

java有原语和参考。这是所有你需要在java。如果要引用对象,则使用引用。这就像一个指针,除了你

  • don't have pointer arithmetic which means the JVM can arrange the objects how it likes.
  • don't use explicit pointer referencing.
  • don't see the underlying address. This means that a 64-bit JVM typically uses 32-bit references up to 64 GB of memory. Something you couldn't do if you used pointer arithmetic.

如何保存最后的地址。

你用这样的作业。

Double d = new Double(1.0);

这将将对象新双(1)的引用保存到变量D中。

请分享一个链接到java读取这个工作的基本。

参考是一个指针,你不能操纵,只复制引用。没有更多的东西。

java为什么这样做?

为开发者保持尽可能简单的事情。他们试图给你最低限度的功能,使代码更容易维护。仍然有很多方法来解决同样的问题,但它避免了大多数复杂的功能。您可能不同意的选择范围,如为什么“签名字节”,而不是“无符号字节”,但他们认为这是意图)

answer2: 回答2:

there is no pointers in java like in c++. Object holds the memory address as a value. to achive that you have to do following.

class List {
Node headNode;


} 

class Node {
Node nextNode;
Node previosNode
 int val; 
}

i might be wrong about the members of node class, but idea is you can implement list using objects.

this may help you in link implementation

there is no pointers in java like in c++. Object holds the memory address as a value. to achive that you have to do following.

class List {
Node headNode;


} 

class Node {
Node nextNode;
Node previosNode
 int val; 
}

我可能错了节点类的成员,但想法是你可以实现使用对象列表。

这可能会帮助您在链路实现

java