Know Your Falsehoods

 class​ NameTag {
 
 final​ String name;
 
  NameTag(String fullName) {
»this​.name = parse(fullName).toUpperCase();
  }
 
  String parse(String fullName) {
  String[] components = fullName.split(​"[,| ]"​);
 if​ (components == ​null​ || components.length < 2) {
 return​ fullName;
  }
 if​ (fullName.contains(​","​)) {
 return​ components[0];
  } ​else​ {
 return​ components[components.length - 1];
  }
  }
 }

We’d like to end the book with a peculiar comparison. No matter what domain you’re in, your code’s just as good as your understanding of the real world and no better. And the real world is complex. That’s why you shouldn’t assume too much and make your code flexible to cope with being proven wrong.

The ...

Get Java By Comparison now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.