Answer the question
In order to leave comments, you need to log in
How to access ENUM which is inside a class?
How to access ENUM which is inside a class?
There is a class Student , which has a ChildrenElements enum inside :
public class Student extends GeneralElement {
private String name;
private String surname;
private String age;
private String course;
private String faculty;
Student(){
super.nameMainElement = "STUDENT";
}
protected void setCourse(String value) {
this.course = value;
}
protected void setName(String value) {
this.name = value;
}
protected void setSurname(String value) {
this.surname = value;
}
protected void setAge(String value) {
this.age = value;
}
protected void setFaculty(String value) {
this.faculty = value;
}
@Override
public String toString(){
return "\nName: " + name +
"\nSurname: " + surname +
"\nAge: " + age +
"\nCourse: " + course +
"\nFaculty: " + faculty;
}
public enum ChildrenElements {
NAME,
SURNAME,
AGE,
COURSE,
FACULTY;
}
}
Answer the question
In order to leave comments, you need to log in
Well, I see 2 options here:
1)
Student student = new Student();
// Student.ChildrenElements.COURSE;
// Например
String enumStr = Student.ChildrenElements.COURSE.toString();
int enumOrdinal = Student.ChildrenElements.COURSE.ordinal();
Why doesn't it work?
There is a generic interface GeneralElement :
public interface GeneralElement {
String getMainElement();
}
public class Student implements GeneralElement {
// тут переменные
public enum ChildrenElements {
NAME,
SURNAME,
AGE,
COURSE,
FACULTY;
}
}
public class Student implements GeneralElement {
// тут переменные
public enum ChildrenElements {
LOGIN,
PASSWORD;
}
}
public void create(GeneralElement general) {
for (general.ChildrenElements enumVar : general.ChildrenElements.values()) {
System.out.println(enumVar);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question