I have a situation where I would like to return 2 values from a method. I am trying to figure out how to do this in Java. In C# I would just use 2 out parameters or a struct in this case but not sure what is best to do for Java (other than Pair as I may have to change this to 3 values, or having to create a new class to return object).
My example is this:
public void myMethod(Signal signal){
MyEnum enum = MyEnum.DEFAULT;
String country = "";
// based on signal, I need to get 2 values, one is string, other is
// an enumeration
if (signal.getAction() == "Toyota"){
enum = MyEnum.TOYOTA;
country = "Japan";
} else if (signal.getAction() == "Honda"){
enum = MyEnum.HONDA;
country = "Japan";
} else if (signal.getAction() == "VW"){
enum = MyEnum.VW;
country = "Germany";
} else {
enum = MyEnum.DEFAULT;
country = "Domestic";
}
// how to return both enum and country?
return ???
}
This is just an example to explain what I need (returning one-something, having 2 values, one is string, other is an enum in this case). So, ignore any issues with my string comparison or logic, my point is how to return something. For example, in C#, I could define a struct and return that struct, or I could use out parameters to return 2 values. But I am not sure how to do that elegantly in Java.