Reputation: 1959
The following java code doesn't compile in eclipse. What am I doing wrong here? It all works ok if the method just returns an int
instead of an enum
so it's basically set up ok. the problem is in introducing the enum return type.
public class myclass {
public enum mytype {
mytype2,
mytype1,
};
public static mytype retmytype() {
return mytype2;
}
}
//in another class
myclass.mytype t = myclass.retmytype(); //ERROR - myclass.mytype cannot be solved
Upvotes: 0
Views: 75
Reputation: 22171
Try to replace return mytype2;
by return mytype.mytype2;
By the way, you should follow Java naming convention ;)
I think you forgot a main method (or any other called methods in your program flow). Try this:
public class myclass {
public enum mytype {
mytype2,
mytype1,
};
public static mytype retmytype() {
return mytype.mytype2;
}
public static void main(String[] args){
myclass.mytype t = myclass.retmytype();
}
}
Upvotes: 1