protected enum Category { Action, Fiction, Drama, Romance, SciFi, Poems, Kids }
我创建了这个枚举类型,现在我必须为我的类创建一个构造函数.
public Book(String title, int code, List authors, String publisher, int year, Category categ){
this.title = title;
this.code = code;
this.authors = authors;
this.publisher = publisher;
this.year = year;
this.category = ....;
}
我不明白我将如何向构造函数传递枚举类型的值.
有人可以帮忙吗?
我知道这是初学者的问题,但我似乎无法在任何地方找到答案.
解决方法:
像这样的东西
new Book( title, ........ ,Category.anyEnumConstant);
例如:
Book book= new Book( title, ........ ,Category.Fiction);
然后在构造函数内部
this.category = categ;
标签:java,enums,constructor
来源: https://codeday.me/bug/20190713/1454481.html