return null

有時侯一個function已經設定了return type which is Node in this case.
如果想要報錯並返回一個非Node的東西時就 return null

public Node min_node() {
		if (root == null) {
			System.out.println("root not exists");
			return null;  //如不想返回Node type就return null
		}
		
		if (root.leftchild == null) {
			return root;
		}
		Node curr = root.leftchild;
		while (curr.leftchild != null) {
			curr = curr.leftchild;
		}
		return curr;   
	}

猜你喜欢

转载自blog.csdn.net/vincentgoodturtle/article/details/94618148