gpt4 book ai didi

java - 当 hashmap 中的键看起来像 :entry. getBname.getTitle() 时,如何识别它

转载 作者:行者123 更新时间:2023-12-02 05:25:54 27 4
gpt4 key购买 nike

当我在做hashmap编码时,我遇到了一个碰撞来识别key,示例如下:

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

对于这个例子,getBname()getTitle 是这个的键吗?,entry 应该是值,对吗?但是entry代表的是一个类,那么是否意味着entry中的所有内容都是值?

感谢您解答我的疑问。

仅供引用: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);

关于java - 当 hashmap 中的键看起来像 :entry. getBname.getTitle() 时,如何识别它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26034965/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com