Example showing that factory methods have greater flexibility when typing with generics
authorJaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:57:11 +0200
changeset 142e220ab4a7afa
parent 141 9ae8488379e0
child 143 20dad4daf81b
Example showing that factory methods have greater flexibility when typing with generics
samples/genericconstructor/build.xml
samples/genericconstructor/nbproject/project.xml
samples/genericconstructor/src-factory/org/apidesign/template/Template.java
samples/genericconstructor/src-generics/org/apidesign/template/Template.java
samples/genericconstructor/src-plain/org/apidesign/template/Template.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/genericconstructor/build.xml	Sat Jun 14 09:57:11 2008 +0200
     1.3 @@ -0,0 +1,37 @@
     1.4 +<?xml version="1.0" encoding="UTF-8"?>
     1.5 +<project name="incompatibilities" default="run" basedir=".">
     1.6 +    <target name="clean">
     1.7 +        <delete dir="build"/>
     1.8 +    </target>
     1.9 +    
    1.10 +    <target name="compile" depends="build"/>
    1.11 +    <target name="build" depends="clean">
    1.12 +        <echo level="info" message="Compiles with 1.4"/>
    1.13 +        <antcall target="-build-one">
    1.14 +            <param name="version" value="plain"/>
    1.15 +            <param name="source" value="1.4"/>
    1.16 +        </antcall>
    1.17 +        <echo level="info" message="Compiles with 1.5"/>
    1.18 +        <antcall target="-build-one">
    1.19 +            <param name="version" value="generics"/>
    1.20 +            <param name="source" value="1.5"/>
    1.21 +        </antcall>
    1.22 +    </target>
    1.23 +    
    1.24 +    <!-- support methods -->
    1.25 +    
    1.26 +    <target name="-build-one">
    1.27 +        <fail message="You need to specify version number" unless="version"/>
    1.28 +        <fail message="You need to specify source number" unless="source"/>
    1.29 +        
    1.30 +        <property name="target" value="${version}"/>
    1.31 +        <mkdir dir="build/${target}/classes"/>
    1.32 +        <javac 
    1.33 +            srcdir="src-${version}" 
    1.34 +            destdir="build/${target}/classes" 
    1.35 +            source="${source}" target="${source}"
    1.36 +            classpath="${cp}"
    1.37 +            failonerror="false"
    1.38 +        />
    1.39 +    </target>
    1.40 +</project>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/samples/genericconstructor/nbproject/project.xml	Sat Jun 14 09:57:11 2008 +0200
     2.3 @@ -0,0 +1,85 @@
     2.4 +<?xml version="1.0" encoding="UTF-8"?>
     2.5 +<project xmlns="http://www.netbeans.org/ns/project/1" xmlns:ns4="null">
     2.6 +    <type>org.netbeans.modules.ant.freeform</type>
     2.7 +    <configuration>
     2.8 +        <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
     2.9 +            <name>genericconstructor</name>
    2.10 +        </general-data>
    2.11 +        <general-data xmlns="http://www.netbeans.org/ns/freeform-project/2">
    2.12 +            <!-- Do not use Project Properties customizer when editing this file manually. -->
    2.13 +            <name>genericconstructor</name>
    2.14 +            <properties/>
    2.15 +            <folders>
    2.16 +                <source-folder>
    2.17 +                    <label>src-plain</label>
    2.18 +                    <type>java</type>
    2.19 +                    <location>src-plain</location>
    2.20 +                    <encoding>UTF-8</encoding>
    2.21 +                </source-folder>
    2.22 +                <source-folder>
    2.23 +                    <label>src-generics</label>
    2.24 +                    <type>java</type>
    2.25 +                    <location>src-generics</location>
    2.26 +                    <encoding>UTF-8</encoding>
    2.27 +                </source-folder>
    2.28 +                <source-folder>
    2.29 +                    <label>src-factory</label>
    2.30 +                    <type>java</type>
    2.31 +                    <location>src-factory</location>
    2.32 +                    <encoding>UTF-8</encoding>
    2.33 +                </source-folder>
    2.34 +            </folders>
    2.35 +            <ide-actions>
    2.36 +                <action name="build">
    2.37 +                    <target>build</target>
    2.38 +                </action>
    2.39 +                <action name="clean">
    2.40 +                    <target>clean</target>
    2.41 +                </action>
    2.42 +                <action name="run">
    2.43 +                    <target>run</target>
    2.44 +                </action>
    2.45 +                <action name="rebuild">
    2.46 +                    <target>clean</target>
    2.47 +                    <target>build</target>
    2.48 +                </action>
    2.49 +            </ide-actions>
    2.50 +            <view>
    2.51 +                <items>
    2.52 +                    <source-folder style="packages">
    2.53 +                        <label>Plain Old Java</label>
    2.54 +                        <location>src-plain</location>
    2.55 +                    </source-folder>
    2.56 +                    <source-folder style="packages">
    2.57 +                        <label>With Generics</label>
    2.58 +                        <location>src-generics</location>
    2.59 +                    </source-folder>
    2.60 +                    <source-folder style="packages">
    2.61 +                        <label>With Factory</label>
    2.62 +                        <location>src-factory</location>
    2.63 +                    </source-folder>
    2.64 +                </items>
    2.65 +                <context-menu>
    2.66 +                    <ide-action name="build"/>
    2.67 +                    <ide-action name="rebuild"/>
    2.68 +                    <ide-action name="clean"/>
    2.69 +                    <ide-action name="run"/>
    2.70 +                </context-menu>
    2.71 +            </view>
    2.72 +        </general-data>
    2.73 +        <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1">
    2.74 +            <compilation-unit>
    2.75 +                <package-root>src-plain</package-root>
    2.76 +                <source-level>1.4</source-level>
    2.77 +            </compilation-unit>
    2.78 +            <compilation-unit>
    2.79 +                <package-root>src-generics</package-root>
    2.80 +                <source-level>1.5</source-level>
    2.81 +            </compilation-unit>
    2.82 +            <compilation-unit>
    2.83 +                <package-root>src-factory</package-root>
    2.84 +                <source-level>1.5</source-level>
    2.85 +            </compilation-unit>
    2.86 +        </java-data>
    2.87 +    </configuration>
    2.88 +</project>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/samples/genericconstructor/src-factory/org/apidesign/template/Template.java	Sat Jun 14 09:57:11 2008 +0200
     3.3 @@ -0,0 +1,17 @@
     3.4 +package org.apidesign.template;
     3.5 +
     3.6 +// BEGIN: generics.constructor.template3
     3.7 +public final class Template<T> extends Object {
     3.8 +    private final Class<T> type;
     3.9 +
    3.10 +    public Template(Class<T> type) { this.type = type; }
    3.11 +    public Class<T> getType() { return type; }
    3.12 +
    3.13 +    @Deprecated
    3.14 +    public Template() { this((Class<T>)Object.class); }
    3.15 +    
    3.16 +    public static Template<Object> create() {
    3.17 +        return new Template<Object>(Object.class);
    3.18 +    }
    3.19 +} 
    3.20 +// END: generics.constructor.template3
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/samples/genericconstructor/src-generics/org/apidesign/template/Template.java	Sat Jun 14 09:57:11 2008 +0200
     4.3 @@ -0,0 +1,13 @@
     4.4 +package org.apidesign.template;
     4.5 +
     4.6 +// BEGIN: generics.constructor.template2
     4.7 +public final class Template<T> extends Object {
     4.8 +    private final Class<T> type;
     4.9 +
    4.10 +    public Template(Class<T> type) { this.type = type; }
    4.11 +    public Class<T> getType() { return type; }
    4.12 +
    4.13 +    // now what!?
    4.14 +    public Template() { this(Object.class); }
    4.15 +} 
    4.16 +// END: generics.constructor.template2
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/samples/genericconstructor/src-plain/org/apidesign/template/Template.java	Sat Jun 14 09:57:11 2008 +0200
     5.3 @@ -0,0 +1,16 @@
     5.4 +package org.apidesign.template;
     5.5 +
     5.6 +// BEGIN: generics.constructor.template1
     5.7 +
     5.8 +import org.apidesign.template.withgenerics.*;
     5.9 +
    5.10 +public final class Template extends Object {
    5.11 +    private final Class type;
    5.12 +
    5.13 +    public Template(Class type) { this.type = type; }
    5.14 +    public Class getType() { return type; }
    5.15 +
    5.16 +
    5.17 +    public Template() { this(Object.class); }
    5.18 +} 
    5.19 +// END: generics.constructor.template1