I have a getSource method that return a Pair<String,String> and I want to call the method and associate the key and the value to two different variables.
I do it like this:
entryMode = getSource(encounterAdmitSource).getKey();
admitSource = getSource(encounterAdmitSource).getValue();
My question is: is there a way in java to do something like that:
getSource(encounterAdmitSource){ //Something
entryMode = getKey();
admitSource=getValue();
}
I want to initialize entryMode and admitSource by call only once the method and without create a Pair<String,String> object.
Does it exist?
Thank you.
Without using Optional, this is the best you could do (safely) for the given example
final Pair<String, String> source = getSource(encounterAdmitSource);
if (source!=null) {
String entryMode = source.getKey();
String admitSource=source.getValue();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With