Wednesday, March 25, 2009

Extensions Methods In Java!

Note: Oracle has locked down java so this is no longer possible :-(


I just added extension methods to java. It's a bit of a hack, but a small bit. (you need to replace the java.lang.Object class)

First, the hack, download and follow the instructions in the readme file of

Now you can run this test successfully...

package com.spun.util.extensions.tests;
import junit.framework.TestCase;

public class ExtensionsTest extends TestCase
public static class MyStringUtils extends ExtendableBase<String>
public String removeVowels()
StringBuffer b = new StringBuffer();
for (Character c : caller.toCharArray())
switch (c)
case 'a' :
case 'e' :
case 'i' :
case 'o' :

case 'u' :
default :
b.append(c); } } return b.toString();
public void testname() throws Exception
String name = "Hello World".use(MyStringUtils.class).removeVowels();
assertEquals("Hll Wrld", name);

Pay extra attention to this line:

"Hello World".use(MyStringUtils.class).removeVowels();

What's more: this use of extensions doesn't have name spacing issues, nor does it pollute all of your objects. It's IDE friendly supporting both code completion and quick fixes!

As a side note, if generics were done better, I would like it to be:

"Hello World".use<MyStringUtils>().removeVowels();

But this is available now! I'll blog more on it tomorrow, but I am very excited about it.

Saturday, January 10, 2009

That which is measured gets done.

The other day at my Letip meeting one of our members, Mikel Bruce, gave a great talk on goal setting.

One of the things he mentioned, which I particularly liked, was a tool called an awareness sheet. The idea is simple, write down all the things you want to do each day: exercise, eat diner as family, limit tv watching, floss etc… then at the end of each day, you check off what you’ve done

The important part here though isn’t in checking off what you’ve done. This is why you don’t check it off as you do it. The important part is the awareness of what you haven’t done. The benefit here is that it isn’t penalizing you for not doing it. It’s not like you have to do everything every day. It’s just making you aware of what you want to do, and if you’re doing it. However, this awareness will help you to actually do it.

Think of it as a small commercial, every night, reminding you what you want. Here’s a small picture of a sample month.

In the end, it's just measuring the habits you want. I'm also finding this useful for events. For example, an presentation awareness sheet. Just to keep me aware of all the details I want to improve when speaking.