Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Philipp Meier http://fnogol.de/

« Newer Snippets
Older Snippets »
Showing 11-12 of 12 total

Class rename friendly log instance

Use the following to automatically use the current class name for the log category (example is for commons-logging, works with log4j, too):

   1  
   2  class Foo {
   3     private final Log log = LogFactory.getLog(getClass());
   4  }


Compare to the following where the class name is refered to explicitely. If the class is renamed or parts of the codes are copied ("reused") the logging will by misleading.

   1  
   2  class Foo {
   3     private static final Log log = LogFactory.getLog(Foo.class);
   4  }



Convert array to java.util.List

   1  
   2  Object[] array = new Object[]{"12","23","34"};
   3  java.util.List list = Arrays.asList(array);
« Newer Snippets
Older Snippets »
Showing 11-12 of 12 total