For example, if I have two classes Director and Follower. I want the Director to tell the follower where to go (ex: follower1.go(direction.LEFT)), and I want the Director to know what directions it can tell the Follower to go when coding in an IDE that gives completion suggestions.I know I can already either do:public void go(String direction);or public void goLeft();public void goRight();public void goUp();public void goDown();But the first won't give me options in an IDE (or at least, I don't know how to show the options), and the second could be hard to maintain for a less trivial function. Ideally, I would like something like,public enum Direction{LEFT, RIGHT, UP, DOWN};public void go(Direction direction);But of course, that doesn't work (at least in Java, and Direction is part of the Follower class). Is there a roundabout way to use enums (or any other way) to get something like the 3rd effect, where I can both limit the parameters of a function, and make it easily visible in an IDE that gives completion suggestions?
Is there a way for Object 1 to call Object 2's enums in a function call?
java;functions;enum;parameters
I think if you remove public, it will work: enum Direction{LEFT, RIGHT, UP, DOWN};though I believe it that this enum will only be accessible to other classes that are in the same package as Follower.Why does Direction need to be contained within the Follower class, when the Director (which I assume is a separate class) will also need to make use of it? If you want to limit the scope of this enum, you could declare it in the same package, but in a separate file. That way you can change it to having public scope when you need it to be accessed elsewhere, and the syntax for accessing it is neater and cleaner, too.