čtvrtek 15. ledna 2009

Private constructor

I started read the Bloch's Effective Java, 2nd edition. I read the 1st edition couple years ago. I must say, that second edition is not only a facelift - there are much more items explained. E.g. generics, concurrent api, etc.

Item 4 (Item 5 in the 1st ed.) is about Protecting utility class with private constructor. When you have some class with only static methods (e.g. Math), it is useful to protect instantiation of this class. Standard way, how to implement it, is by private default constructor.

public class MuUtilClass {
private MyUtilClass(){}
// other methods omitted
}

Joshua find out, that you can change the accesibility of the constructor by reflection (AccessibleObject.setAccesible). Hence it is better to throw exception inside the constructor.

public class MuUtilClass {
private MyUtilsClass() {
throw new AssertionError();
}
// other methods omitted
}

čtvrtek 8. ledna 2009

Launchy

Pozor, následující prográmek je vysoce návykový.


Jde o spouščeč programů launchy. Prohledá vám hardisk a pak už to frčí. Po stisku ALT-Space otevře miniaturní textfield do kterého můžete začíst psát. Třeba 'word' a spustí vám Office Word.

Mě pomáhá zejména s vyhledáváním knížek, které okupují značnou část mého disku. Napíšu třeba 'spring' a hned mi ukáže všechny knížky o springu.

Myš už můžu vyhodit z okna ;-).