【发布时间】:2014-11-08 19:01:06
【问题描述】:
我对 Java 语言比较陌生,并且有一个我正在为学校做的项目,其中我有一个 Book 类,它具有该类的普通 setter/getter、构造函数和覆盖,没有什么复杂的。我必须更改它,以便我可以通过使用 Set 和 HashSet 获得多个作者。我的问题是我将如何去做这件事?到目前为止,如果我错了,请纠正我,我有这个
import java.util.*;
public class Book{
private Set<String> authorSet;
private String isbn;
public Book(){
authorSet = null;
isbn = null;
}
public Book(String isbn, Set<String> authorSet){
this.isbn = isbn;
Set<String> s = new HashSet<String>();
// Do I do anything else here?
}
public String getIsbn(){
return isbn;
}
public void setIsnb(String isbn){
this.isbn = isbn;
}
public Set<String> getAuthorSet(Set<String> newAuthorSet{
return newAuthorSet;
}
public void setAuthorSet(Set<String> newAuthorSet){
this.authorSet = newAuthorSet;
}
在继续进行覆盖之前,我想确保我正确理解了这一点。我试图寻找类似的例子,这样我就可以看到发生了什么,但到目前为止我还没有多少运气。我敢肯定这很简单,但我才刚刚开始学习这门语言。感谢您的帮助
【问题讨论】:
-
你有什么问题?您是指会阻止编译的拼写错误吗?
标签: java collections set hashset