Node类Java可选参数

时间:2017-10-10 05:04:23

标签: java node.js

我对Java很陌生,想知道如何创建Node类。这就是我得到的

Node.java(接口)

public interface Node {



  /**
   * get the nodes id.
   * @return the id of the node.
   */
  public int getId();

  /**
   * Checks if nodes have same id.
   * @param n the node to be compared to.
   * @return true if nodes have same id, false otherwise.
   */
  public boolean equals(Node n);
}

NodeImpl.java(实现)

public class Nodelmpl implements Node {

  private int data;
  private Node next;

  public Nodelmpl(int data, Node next) {
    this.data = data;
    this.next = next;
  }

  @Override
  public int getId() {
    // TODO Auto-generated method stub
    return data;
  }

  @Override
  public boolean equals(Node n) {
    // TODO Auto-generated method stub
    return this.data == n.getId();
  }

}

我相信下一个不是可选的?

在Python中我可以写

a = Node(1, Node(2, Node(3)))

获取a的基本链接列表:1-> 2-> 3->无如何用Java编写?

0 个答案:

没有答案