Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyClass<T extends Enum<T>> {
- public void setFoo(T[] foos) {
- ....
- }
- }
- <bean id="myClass" class="example.MyClass">
- <property name="foo">
- <list>
- <value>ONE</value>
- <value>TWO</value>
- </list>
- </property>
- </bean>
- <bean id="myClass" class="example.MyClass">
- <property name="foo">
- <list value-type="example.MyEnumType">
- <value>ONE</value>
- <value>TWO</value>
- </list>
- </property>
- </bean>
- <bean id="myClass" class="example.MyClass">
- <property name="foo">
- <list>
- <value>ONE</value>
- <value>TWO</value>
- </list>
- </property>
- </bean>
- <bean id="simpleInt" class="org.nipr.gateway.service.transaction_assistant.GenericSimple">
- <constructor-arg>
- <value>java.lang.Integer</value> <!-- this can be any full path to a class -->
- </constructor-arg>
- <bean id="simpleString" class="org.nipr.gateway.service.transaction_assistant.GenericSimple">
- <constructor-arg>
- <value>java.lang.String</value>
- </constructor-arg>
- public class GenericSimple {
- private Class type;
- public GenericSimple(Class type) {
- this.type = type;
- }
- public T get( T t)
- {
- return t;
- }
- }
- public void testGeneric(){
- Factory factory = new Factory( new String[]{ "config/beanForGenericTest.xml"} );
- GenericSimple simpleInt = (GenericSimple)factory.getClass("simpleInt");
- System.out.println( simpleInt.get( new Integer(100)) );
- Assert.assertTrue(simpleInt.get( new Integer(100)) == 100 );
- GenericSimple simpleString = (GenericSimple)factory.getClass("simpleString");
- System.out.println( simpleString.get( new String("Rockets go fast.")) );
- Assert.assertTrue(simpleString.get( "Rockets go fast.").equals("Rockets go fast.") );
- }
Add Comment
Please, Sign In to add comment