The best way to implement a Singleton

OWH. MY. GOD.

The more I study about OCPJP, the more I make clear how stranger I am to this language.

Guys, herewith I share with you ta code-snippet:

public enum Employee {
    INSTANCE;
}

Owh, sorry, April’s fool in September, that wasn’t a code snippet, it was an implementation of the Singleton pattern.

Below you can read Joshua’s Block view about this, from his Effective Java book:

This approach is functionally equivalent to the public field approach, except that it is more concise, provides the serialization machinery for free, and provides an ironclad guarantee against multiple instantiation, even in the face of sophisticated serialization or reflection attacks. While this approach has yet to be widely adopted, a single-element enum type is the best way to implement a singleton.

Advertisements

Get rid of any react-transform-hmr remnant!

Get rid of any react-transform-hmr remnant!

1. Introduction

Sunday night, preparing another small javascript project and struggling with a few dependencies.

2. The Problem

Copy-pasting configurations some times goes wrong of course, so I ended up like below:

83e632eb7c5cac296071836a3e3688a9

3. The Solution

3.1 react-hot-loader

Navigating to link the error stack returned, I found out I should better give a try to the descendant of react-transform-hmr: react-hot-loader

3.2 Minimal configuration in .babelrc

If you just check the configuration in react-hot-boilerplate, you kinda understand the big of a change that we went through, you only have to define one line in your .babelrc file:

{
  "presets": ["es2015", "react", "stage-2"]
}

3.3 Update package.json

In addition, given the situation above, ensure you install the respective dependency:

npm install --save-dev babel-preset-stage-2

Cheers!