Guest User

Untitled

a guest
Jun 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. public class MyClass<T extends Enum<T>> {
  2. public void setFoo(T[] foos) {
  3. ....
  4. }
  5. }
  6.  
  7. <bean id="myClass" class="example.MyClass">
  8. <property name="foo">
  9. <list>
  10. <value>ONE</value>
  11. <value>TWO</value>
  12. </list>
  13. </property>
  14. </bean>
  15.  
  16. <bean id="myClass" class="example.MyClass">
  17. <property name="foo">
  18. <list value-type="example.MyEnumType">
  19. <value>ONE</value>
  20. <value>TWO</value>
  21. </list>
  22. </property>
  23. </bean>
  24.  
  25. <bean id="myClass" class="example.MyClass">
  26. <property name="foo">
  27. <list>
  28. <value>ONE</value>
  29. <value>TWO</value>
  30. </list>
  31. </property>
  32. </bean>
  33.  
  34. <bean id="simpleInt" class="org.nipr.gateway.service.transaction_assistant.GenericSimple">
  35. <constructor-arg>
  36. <value>java.lang.Integer</value> <!-- this can be any full path to a class -->
  37. </constructor-arg>
  38.  
  39. <bean id="simpleString" class="org.nipr.gateway.service.transaction_assistant.GenericSimple">
  40. <constructor-arg>
  41. <value>java.lang.String</value>
  42. </constructor-arg>
  43.  
  44. public class GenericSimple {
  45. private Class type;
  46. public GenericSimple(Class type) {
  47. this.type = type;
  48. }
  49. public T get( T t)
  50. {
  51. return t;
  52. }
  53. }
  54.  
  55. public void testGeneric(){
  56. Factory factory = new Factory( new String[]{ "config/beanForGenericTest.xml"} );
  57. GenericSimple simpleInt = (GenericSimple)factory.getClass("simpleInt");
  58. System.out.println( simpleInt.get( new Integer(100)) );
  59. Assert.assertTrue(simpleInt.get( new Integer(100)) == 100 );
  60. GenericSimple simpleString = (GenericSimple)factory.getClass("simpleString");
  61. System.out.println( simpleString.get( new String("Rockets go fast.")) );
  62. Assert.assertTrue(simpleString.get( "Rockets go fast.").equals("Rockets go fast.") );
  63. }
Add Comment
Please, Sign In to add comment