samples/conditionaluseofapi/src/conditionaluseofapi/Main.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:50:50 +0200
changeset 6 b577ee7fcf67
child 132 3bc4c54f4bcc
permissions -rw-r--r--
example with conditional usage of an API
     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             add = (AddString)Class.forName("conditionaluseofapi.StringBuilderAdd15").newInstance();
    28         } catch (ClassNotFoundException ex) {
    29             add = new StringBufferAdd();
    30         }
    31         // END: theory.binary.overloads.init
    32         
    33         add.addString("Hello");
    34         add.addString(" ");
    35         add.addString("World!");
    36         
    37         System.out.println(add.getMessage());
    38         System.out.println("printed with: " + add);
    39     }
    40 
    41 }