samples/conditionaluseofapi/src/conditionaluseofapi/StringBuilderAdd15.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:50 +0200
changeset 6 b577ee7fcf67
permissions -rw-r--r--
example with conditional usage of an API
     1 package conditionaluseofapi;
     2 
     3 /** Implementation for string concatention using Java 5 only.
     4  * 
     5  * StringBuilder is supposed to be faster than StringBuffer as it
     6  * is not synchronized and as such it is does not waste time with
     7  * synchronization when its methods are called. 
     8  *
     9  * @author Jaroslav Tulach <jtulach@netbeans.org>
    10  */
    11 final class StringBuilderAdd15 implements AddString {
    12     
    13     private StringBuilder sb = new StringBuilder();
    14 
    15     public void addString(String msg) {
    16         sb.append(msg);
    17     }
    18 
    19     public String getMessage() {
    20         return sb.toString();
    21     }
    22 
    23     public String toString() {
    24         return "New Shiny and Fast Java 5 Implementation";
    25     }
    26 }