Archive: December 2020

Java Joy: Optional orElse orElseGet That Is The Question

Posted on by  
Hubert Klein Ikkink

The Optional class has the orElse and orElseGet methods to return a value when the Optional object is empty. This is useful to return a default value for example. But there is a small difference between the two methods. The orElseGet method needs a Supplier argument that returns a value of the type of the Optional value. The Supplier is only invoked when the Optional value is empty. The statement passed as argument to the orElse method is always executed, even when the Optional value is not empty. Preferrably we should use orElseGet as it will only invoke statements if needed.

In the following example code we see when our method getDefaultGreeting is invoked by using orElse and orElseGet with an empty and non-empty Optional object:

Continue reading →

iTerm2

Posted on by  
Justus Brugman

Since I’ve been working on a Mac, I replaced the default terminal with iTerm2. It provides some nice features like searching, autocomplete, or allowing to see images in the terminal. But this one is my favorite one, the undo close tab / session.

Don’t you just hate it when you have multiple terminal tabs open, and accidentally close one? Just that one where you had an important process running, or tailing an error log? I do! :) This is just a short blogpost how iTerm2 helps me having more fun using my terminal. Actually it’s not much of a blogpost, this provides some screenshots. Sometimes an image says more than words.

Continue reading →

shadow-left