class Scroll {
static boolean up;
static boolean down;
public static void scroll(boolean direction) {
if (/* ... */) {
System.out.println("UP");
}
else {
System.out.println("DOWN");
}
}
public class Test2 {
public static void main(String[] args) {
Scroll.scroll(Scroll.up);
}
}
How can I check which field has function been called with – with Scroll.up or Scroll.down? I know that in above code I could get same effect in other way, but it’s simplified code with essence of my problem.
If the only choices are up or down, you can rename
directionasupand then:If there are more directions (left and right, for instance), or even if not really, this is where
enumis handy:Then use that in your code, possibly with a
switch:More about enums.