I've been wondering for quite some time now why they chose to use int
parameters for some classes in java to pass in variable options for
methods, say for instance JOptionPane's method showConfirmDialog
where the 4th parameter is of type int and you have to pass in one of
the static JOptionPane member variables to call that method. Why
wouldn't they create some type of internal class that can handle
these situations in what seems to me a more logical way. I've created
2 test classes, Test and it's test driver Test2, to show what I'm
thinking. Test is a class that needs a parameter passed into the
constructor that is one of it's static member variables, but I'm
choosing to use an instance of a static private class for that
variable instead of an int. Is there something that I'm missing that
wouldn't make this a better approach? Any comments would be
interesting because it's just basically a pondering of mine.
public class Test{
public static ConsoleType GUI = new ConsoleType(1);
public static ConsoleType CONSOLE = new ConsoleType(2);
Test(ConsoleType init){
if(init.equals(Test.GUI))
System.out.println("gui");
else
System.out.println("console");
}
private static class ConsoleType{
private int number;
ConsoleType(int number){
this.number = number;
}
public boolean equals(Object test){
if(test instanceof ConsoleType && this.number ==
((ConsoleType) test).number)
return true;
else
return false;
}
}
}
public class Test2{
public static void main(String args[]){
Test myTest = new Test(Test.CONSOLE);
}
}