Relaxing visibilities using Javassist

October 25, 2010

I personally like to restrict the visibility of my classes and members as much as possible. However, package-private classes get quickly annoying when used in an interactive environment such as the Scala interpreter. When we encountered this problem with one of our internal tools, we decided to generate derived versions of our JAR files with… Read more

When Garbage Collection is Failure

September 14, 2010

For systems that absolutely require a constant responsiveness Java is generally not an option because of the pauses associated with the garbage collector. Even the alternative collectors, such as parallel and concurrent-mark-sweep, have a pause associated with them for major and minor collections. This problem can be avoided, though, by making sure the garbage collector… Read more

Type inference puzzler

August 31, 2010

Does this compile? public class Puzzle { static Object one() { return 1; } static <T> T safeOne() { return (T) one(); } public static void main(String[] args) { int one = safeOne(); System.out.println(one); } } Take a look at it carefully and think before answering. Why or why not? Once you’ve thought it through,… Read more

Creating TypeLiterals in Scala

August 30, 2010

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, { case n: ClassManifest[_] => typeLiteralOf(n).getType }.toArray))… Read more

Type Safe Bit Fields Using Higher-Kinded Polymorphism

August 13, 2010

Refering to securities, such as stocks or bonds, is far from standard. We all know Apple’s ticker AAPL; But what about the Oracle of Omaha’s company Berkshire Hathaway? Google says BRKA, Yahoo! BRK-A, Bloomberg BRK/A and Reuters BRKa. Due to these oddities, every serious automated trading system like kaChing’s has at its core a powerful… Read more

I Can Has Invariant Mapz?

July 29, 2010

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… Read more