Compare enums with == instead of equals() in Java

November 22nd, 2017 | #java

TIL you should compare enums with == instead of equals() in Java.

a == SomeEnum.ENUM_VALUE
/* instead of */
a.equals(SomeEnum.ENUM_VALUE)
Read more

Passing Default group to form(...) in Play 2.6.x when using group constraints in forms

November 17th, 2017 | #java #playframework

TIL if you pass custom groups to the form(...) method in Play 2.6.x, you also have to pass the group javax.validation.groups.Default explicitly—if you want any of its fields taken into account during the validation process of a form.

Form<FooForm> form = formFactory().form(FooForm.class, Default.class, FooCheck.class).bindFromRequest();
Read more

HashSet in Java is backed by a HashMap instance

November 12th, 2017 | #java

TIL that a HashSet in Java is backed by a HashMap instance.

/**
 * Constructs a new, empty set; the backing <tt>HashMap</tt> instance has
 * default initial capacity (16) and load factor (0.75).
 */
public HashSet() {
    map = new HashMap<>();
}
Read more

Effectively final variables in Java

November 10th, 2017 | #java

TIL what effectively final variables in Java are.

A variable or parameter whose value is never changed after it is initialized is effectively final.

The Java™ Tutorials: Local Classes

Read more

In Java 6 == 24

November 3rd, 2017 | #java

TIL that in Java 6 == 24. Let's see how and why.

Read more

How to run JShell on Mac OS X when Java 8 and Java 9 are installed

November 2nd, 2017 | #java #macos #terminal

TIL how to run JShell on Mac OS X when both Java 8 and Java 9 are installed. JShell is one of the new features in Java 9. It is a REPL (Read Evaluate Print Loop) for Java, which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.

Read more

Escape single quotes when using Java MessageFormat

November 2nd, 2017 | #java

If you are using Java MessageFormat, you will possibly encounter the issue that single quotes are not rendered.

/* string used in code */
"Hello, it's me!"

/* output */
"Hello, its me!"
Read more

Keep track of datetime an entity was last modified with Ebean in Play

October 31st, 2017 | #ebean #playframework #java #sql

TIL that Ebean helps you to keep track of the datetime an entity was last modified. I wanted to implement a column last_modified_at, when a colleague showed me this commit. You simply can add a timestamp property to a model with the annotation @WhenModified. Ebean will set the timestamp to the datetime when the entitiy was last modified.

Read more

© 2018 Tonny Garić | With from Nijmegen, The Netherlands