Kevin Peterson
Kevin Peterson

When all else fails, check the documentation

I ran into a bug in my code today because I didn’t implement clone in a class that needed it (it’s used for rescheduling a failed task). Naturally, I went to fix the code to make these errors impossible through the magic of Type Safety, but Java wasn’t playing fair. It turns out this doesn’t […]

April 09, 2011

Julien Wetterwald

Creating TypeLiterals in Scala

In case anyone wondered, here is how one can easily create instances of Google Guice’s TypeLiteral in Scala. Type literals are used for reifying types. def typeLiteralOf[T](implicit m: scala.reflect.Manifest[T]): TypeLiteral[T] = (m match { case m: ClassManifest[T] if m.typeArguments.isEmpty => TypeLiteral.get(m.erasure) case m: ClassManifest[T] => TypeLiteral.get(new ParameterizedTypeImpl(m.erasure, m.typeArguments.map { case n: ClassManifest[_] => typeLiteralOf(n).getType }.toArray)) […]

August 30, 2010

Julien Wetterwald

I Can Has Invariant Mapz?

If I had to pick one of the major source of bugs in large refactorings I recently went through, it would probably be the bunch of methods in the java.util.Map interface which are contravariant on the key type. For instance, one can retrieve an element from a map using a supertype of its key type […]

July 29, 2010

Adam Rosien

Ids and Ambiguous Method Parameters

You’ve probably run into a method with a signature like: void addToGroup(long userId, long groupId) and a common question you might ask yourself is, “Oh, was it the user id first, or the group id first? I always forget. Stupid method.” You’ve encoded the meaning of the parameters into their names, and hence you need […]

March 14, 2010