Archives for April, 2008
A live template for Java 5 Locks
Saturday, April 26th, 2008
Every time I used Java 5 new locks I found myself writing the same lock.lock(); try {…} finally {lock.unlock();} over and over again. Sometimes I’ve even coded, unintentionally, a lock.lock() instead of a lock.unlock(). Because of this and other reasons which I won’t share (i.e., I don’t like to copy & paste stuff) I [...]
Binding data to Java enums…
Friday, April 25th, 2008
Paul Stovell blogged about binding data to enums in C#. Here is how I would implement this technique in Java….
First, an annotation that I will use to bind data to my enum
@Target(Element.FIELD)
@Retention(RententionPolicy.RUNTIME)
public @interface Config {
String name();
String alias();
}
Then, here is my enum
public enum Role {
@Config(name="James Bond", alias = "Agent 007")
AGENT;
// static attribute that will allow us [...]
Debugging windows services in .NET
Saturday, April 19th, 2008
The other day I was trying to test a Windows Service that I implemented for a friend. I thought to myself that this was going to be an easy endeavor. I just needed to install the service, run it, set some breakpoints, then attach its process to the debugger and that was it. Oh boy… [...]
Sharing Class names: a bad, bad practice….
Saturday, April 19th, 2008
I consider sharing class names (in design or implementation) a bad, bad practice. In my opinion, it is a practice that will lead to confusion among developers, will eventually cause problems, and will promote software entropy.
You don’t have to go that far to find an example of this bad practice. You can find it right [...]