Advertisement
Guest User

Untitled

a guest
Sep 21st, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. String[] words = wordBag.toArray();
  2. String[] dict = dictBag.toArray();
  3.  
  4. Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
  5.  
  6. // public <T> T[] toArray() //OK
  7. public T[] toArray() //OK
  8. {
  9. // the cast is safe because the new array contains null entries
  10. @SuppressWarnings("unchecked")
  11. T[] result = (T[])new Object[numberOfEntries]; // unchecked cast
  12.  
  13. for (int index = 0; index < numberOfEntries; index++)
  14. {
  15. result[index] = bag[index];
  16. } // end for
  17.  
  18. return result;
  19. } // end toArray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement