turt2live

Untitled

Mar 5th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. private static enum Test{
  2.     TEST1, TEST2;
  3. }
  4.  
  5. private class<T> TestClass{
  6.  
  7.     Map<T, String> map = new HashMap<T, String>();
  8.  
  9.     public void add(T obj, String name){
  10.         map.put(obj, name);
  11.     }
  12.    
  13.     public String get(T obj){
  14.         return map.get(obj);
  15.     }
  16.    
  17. }
  18.  
  19. // Somewhere... such as a unit test
  20.  
  21. TestClass<Test> test = new TestClass<Test>();
  22. assertNull(test.get(Test.TEST1));
  23. test.add(Test.TEST1, "somename");
  24. assertNotNull(test.get(Test.TEST1)); // FAILS TO ASSERT
Advertisement
Add Comment
Please, Sign In to add comment