Effective Programming

Kotlin – Regulate a set of broadcasts to listener via Mediator Pattern

The definition of “mediator” is, a person who attempts to make people involved in a conflict come to an agreement; a go-between. Problem Solution The Mediator pattern suggests that all direct communication should be ceased between the components. Instead, these components must collaborate indirectly, by calling a special mediator object that redirects the calls to... » read more

Kotlin – Tips & Tricks

You may try this with Kotlin Playground -> Swap two values w/o temp variable a = b.also { b = a } is equivalent to followings: Enum Reverse Look-up

Kotlin – Idiomatic Way to Deal with Null-able

In Kotlin, a null-able value without being sure it is not null cannot be accessed. (Checking for null in conditions), or asserting that it is surely not null using the !! sure operator, accessing it with a ?. Safe Call, or lastly giving something that is possibly null a default value using the ?: Elvis... » read more

Kotlin – How to achieve Open-Closed Principle with Enum

Kotlin/Java enums are very powerful and important part of the Java language. Even though they can do so much, it is very common to see them either being used incorrectly or not used at all. In this blog post I want to remind you what Java enums can do and show some of the usage... » read more

Kotlin – How to Make Use of Extension Methods

Extension methods enable you to “add” methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Add retry() into Java Runnable class Reference Extension Methods in C#

Kotlin – Use EnumSet For RBAC

Enumset is a powerful collection in Java to replace bit fields. This article will explains how to use EnumSet to create a RBAC (Role-Based Access Control). Now, let’s see how we can use EnumSet to create a RBAC. Inside the setup method, a series of roles with specific access right in a given system has been defined... » read more

Java – Why you should use Optional

To Overcome NullPointerException The Java 8’s Optional is meant for alleviating the occurrence of NullPointerException. NullPointerException is the result of Null References, Null Reference is also known as The Billion Dollar Mistake. The Billion Dollar mistake was coined by a British computer scientist, Sir Charles Antony Richard Hoare. Null pointers are the single biggest source... » read more

Java – How to compare strings

== is to compare 2 object whether are of the same reference equality (whether they are the same object). .equals() tests for value equality (whether they are logically “equal”). Objects.equals() checks for null before calling .equals() so you don’t have to check null to avoid NPE. (available since JDK7, also available in Guava). String.contentEquals() compares... » read more