Contracts for Java

I personally like the idea of Design By Contract very much. The bad news is that Java does not support this natively.

The good news is that there are several libraries out there that try to implement DBC for Java:

Another bad news is that most of these projects are inactive or don’t support all aspects of DBC.

Most feature complete is the Java Modeling Language (JML). There are many tools based on this behavioral interface specification language. I checked some of them but they all seem to be very Academic and not very handy to use.

Now there is a more practical approach that uses annotations to express pre conditions, post conditions and invariants:

A detailed report that introduces the ideas behind the framework can be found here.

This looks very promising and is definitely worth giving it a try!


2 thoughts on “Contracts for Java

    1. Cofoja is a significant rewrite of ModernJass. They worked closely with the original author of ModernJass (Johannes Rieken) on Cofoja. ModernJass itself uses JML expressions for defining assertions.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s