protected enum Category { Action, Fiction, Drama, Romance, SciFi, Poems, Kids }
我已经创建了这个enum
类型,现在我必须为我的类创建一个构造函数。
public Book(String title, int code, List<String> 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);
For ex:
Book book= new Book( title, ........ ,Category.Fiction);
然后在构造函数里面
this.category = categ;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)