vendredi 21 décembre 2018

Java alternative of bad looking if-else or switch constructions

Looking for modern way to realise String translation to replace bad looking if-else or switch constructions:

if ("UK".equals(country)) 
     name = "United Kingdom";
  if ("GE".equals(country))
     name = "Germany";
  if ("FR".equals(country))
     name = "France";
  if ("IT".equals(country))
     name = "Italy";
  [...]

or

switch (country) {
      case "UK": name = "United Kingdom"; break;
      case "GE": name = "Germany" break;
      case "FR": name = "France"; break;
      case "IT": name = "Italy" break;
  [...]

Aucun commentaire:

Enregistrer un commentaire