在进行哈希图编码时,碰到了一个识别密钥的示例,如下所示:

public void addBE(BookEntry entry)
{
library.put(entry.getBname().getTitle(), entry);
}


因此,在此示例中,getBname()getTitle是此键吗?输入的值应该正确吗?但是入口代表一个类,所以这意味着入口中的所有东西都是价值吗?

感谢您澄清我的疑问。

仅供参考:BookEntry类:

public class BookEntry{
private BookName bname;
private Writer wname;
private BookID b_id;

public BookEntry(BookName bname, Writer wname, BookID b_id)
{
this.bname = bname;
this.wname = wname;
this.b_id = b_id;
}

public BookName getBname()
{
return bname;
}
public Writer getWname()
{
return wname;
}
public BookID getBookID()
{
return b_id;
}
public String toString()
{
return bname.toString() + " " + wname.toString() + " " + b_id.toString();
}

public static BookEntry enterBE()
{
BookName bname = BookName.enterName();
Writer wname = Writer.enterWriter();
BookID b_id = BookID.enterID();
return new BookEntry(bname, wname, b_id);
}
}

最佳答案

关键是标题,即getTitle()的输出。它将与以下内容相同:

String titleKey = entry.getBname().getTitle(); // assuming title is a String, but it could be any type
library.put(titleKey, entry);

10-08 18:41