Enforcing State Transitions

To access some service we are using a third-party library with an interface that looks like this: [java]public class Session { public void connect(); public Answer ask(Question question); public void disconnect(); }[/java] The contract specified in the documentation specifies that: The first method invoked on the object may only be connect. The connect method may […]

Maps with Variable Value Types

About Maps and Generics Since Java introduced Generics, Maps became a bit safer to use. Before generics, this code would pass compilation without issues: [java]Map fruitColours = new HashMap(); fruitColours.put(Fruit.banana, “blue”); /* In a method somewhere else */ if (fruitColour.get(“banana”) == Colour.blue) { throw new IllegalStateException(“Alien blue bananas not supported”); }[/java]