Immutable Value Objects in Java with Google AutoValue

Java 8 addressed many of the biggest pain points in the Java language, from lambda expressions and functional-style collection operations to the new Joda-like date and time API.

One notable miss is something like Scala’s case classes or Kotlin’s data classes: a simple way to define immutable value objects. The amount of boilerplate for a class holding just a couple of fields is ridiculous: you need not just a constructor, member variables and setters but most likely also equals, hashCode, and toString implementations, resulting in 50 lines of code in Java versus 1 line in Scala.

Attempts to make things easier range from IDE code generation to the Project Lombok hack. Thankfully, 20 days ago Google released version 1.0 of AutoValue, arguably the best solution to date.

Continue reading

A look at RoboVM: iOS apps in Java

RoboVM is one of the projects I’ve been keeping a close eye on for a while now. Its aim is to allow native iOS apps to be developed in Java. With its recent 1.0 beta 2 release I thought it was time to take it for another spin.

If you ever tried maintaining an app with two separate codebases for Android and iOS at some point you probably wished for a way to share code between the two, reducing duplication and saving development time. I certainly did. And so did Google for their Inbox app apparently – they ended up writing their J2ObjC Java to Objective C transpiler.

Continue reading

Testing Amazon SQS locally with ElasticMQ

If you’re developing an application that uses the Amazon Simple Queue Service (SQS), you may find yourself asking how you can run and test your application locally without having to connect to the real SQS every time. At least, I did – when running our test suite was getting painfully slow.

Luckily, there is at least one option: ElasticMQ provides an SQS-compatible interface.

Continue reading

Scala 2.10 reflection experiments

Scala 2.10.0 is now officially available and includes a new reflection API. The relevant section of the official documentation is still largely missing though, and the feature is marked as “experimental” – with thread-safety being a known issue.

To take it for a spin, I wrote a simple library to serialize and deserialize objects in JSON format, using reflection to auto-detect field names and types. The code is available at Github as Seriala.

Continue reading