Zach Cochran
by Zach Cochran
~1 min read



Maybe I’m stupid (or tired) for not just assuming, but I didn’t even think to check if java supported ternary expressions before starting on some of those problems yesterday. Based on feedback from one of the mentors, I now know that Java does indeed support ternary expressions.

And they work just the same as they do in javascript, which works out great for me!

Nothing too exciting to talk about, but this was how I was able to refactor one of the problems from yesterday:

String twofer(String name) {
   if (name != null) {
       return "One for " + name + ", one for me.";
   } else {
       return "One for you, one for me.";


String twofer(String name) {
   return name != null ? "One for " + name + ", one for me." : "One for you, one for me.";

Oh yeah…

And I also learned that you can’t declare strings with single ticks, so that’s a lot of fun. Python suggested doubles, then javascript had me switch over to singles, and now we’re back to doubles again. Oi.