Java 使用节点的空指针

Java 使用节点的空指针,java,null,Java,Null,我在将(二叉树的)节点与null 假设节点是树的新根,并且key=5 在构造函数中,我将节点的左、右和父节点设置为null (字段:private Node left=null,right=null,parent=null; 构造函数:this.key=key) 当我打印节点的左侧子节点(与右侧和父节点相同)时,我得到了预期的null 但是,node.left==null(或node.getLeft()==null)获取我的false。为什么? 下面是节点类的代码: public c

我在将(二叉树的)节点与
null

假设节点是树的新根,并且
key=5

在构造函数中,我将节点的左、右和父节点设置为
null

(字段:
private Node left=null,right=null,parent=null;
构造函数:
this.key=key

当我打印节点的左侧子节点(与右侧和父节点相同)
时,我得到了预期的null

但是,
node.left==null
(或
node.getLeft()==null
)获取我的
false
。为什么?

下面是节点类的代码:

      public class Node{
        private Node parent = null, left = null, right = null;
        private int key; 

        public Node(int key) {
            this.key = key;
        }

        public Node getParent() {
            return parent;
        }

        public Node getLeft() {
            return left;
        }

        public Node getRight() {
            return right;
        }

        public void setParent(Node parent) {
            this.parent = parent;
        }

        public void setLeft(Node child) {
            this.left = child;
        }

        public void setRight(Node child) {
            this.right = child;
        }

        public void setKey(int key) {
            this.key = key;
        }
  }

请发布在post中添加的节点类的代码,用于此输入:节点n=新节点(5);System.out.println(n.left+“”+n.right+“”+n.parent+“”+n.key);System.out.println(n.left==null);如果使用getLeft()方法,我会得到:null 5 true相同。。。你怎么称呼它?