http : // www . adjective . org /




Uniform is a java class library supporting runtime supertyping. In practice, that makes it somewhat like Latent Typing or Duck Typing.


Most developers would be familiar with the concept of subtyping, where a new type is defined by extending (or specialising) an existing type. e.g. is a subtype of

Supertyping is the same thing, but in the opposite direction, where a new type is defined by generalising from existing types. This is not a feature directly supported by Java, but it is used in the Sather programming language.

For example, we can look at the classes in and the classes in java.sql, and see that many of them have a method named close that takes no arguments, and returns no value. If java supported supertyping could then say:

interface Closeable generalises Reader , Writer , InputStream , OutputStream , Connection , Statement , ResultSet {
  void close() throws Exception ;
Unfortunately, java doesn't support that syntax, and the java runtime environment doesn't make it easy to add directly - i.e. You would need to modify the class files for all those types in order to add an interface to their hierarchy, and you can't reasonably do that in java. But what we can do, is make use of reflection and dynamic proxies, to add a similar feature at runtime. The uniform library refers to this as runtime supertyping.

Duck Typing

Duck typing is a term used in the Ruby community to refer to the form of latent typing that the Ruby language implements. The basic concept is that you don't need to create a type called "Closeable" just to mark the classes that implement the close method, instead, you should write a method that says "I need an object that has a 'close' method on it". So, you define your contracts around behaviours, rather than types.

Uniform is not Duck Typing, but it approximates it within the java runtime environment.