samples/conditionaluseofapi/src/conditionaluseofapi/Main.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:56:12 +0200
changeset 132 3bc4c54f4bcc
parent 6 b577ee7fcf67
child 153 b5cbb797ec0a
permissions -rw-r--r--
Truncating all examples to 80 characters per line
     1 /*
     2  *                 Sun Public License Notice
     3  * 
     4  * The contents of this file are subject to the Sun Public License
     5  * Version 1.0 (the "License"). You may not use this file except in
     6  * compliance with the License. A copy of the License is available at
     7  * http://www.sun.com/
     8  * 
     9  * The Original Code is NetBeans. The Initial Developer of the Original
    10  * Code is Jaroslav Tulach. Portions Copyright 2007 Jaroslav Tulach. 
    11  * All Rights Reserved.
    12  */
    13 package conditionaluseofapi;
    14 
    15 /**
    16  *
    17  * @author Jaroslav Tulach <jtulach@netbeans.org>
    18  */
    19 public class Main {
    20     
    21     public static void main(String[] args) throws Exception {
    22         // BEGIN: theory.binary.overloads.init
    23         AddString add;
    24 
    25         try {
    26             Class onlyOn15 = Class.forName("java.lang.StringBuilder");
    27             Class codeOn15 = Class.forName(
    28                 "conditionaluseofapi.StringBuilderAdd15"
    29             );
    30             add = (AddString)codeOn15.newInstance();
    31         } catch (ClassNotFoundException ex) {
    32             add = new StringBufferAdd();
    33         }
    34         // END: theory.binary.overloads.init
    35         
    36         add.addString("Hello");
    37         add.addString(" ");
    38         add.addString("World!");
    39         
    40         System.out.println(add.getMessage());
    41         System.out.println("printed with: " + add);
    42     }
    43 
    44 }