Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. I've been staring at the screen the last 5 minutes and can't seem to figure out what I'm doing wrong:
  2.  
  3. class Example {
  4.  
  5. private final Set<String> values;
  6.  
  7. public Example(String... values) {
  8. values = new HashSet<String>(Arrays.asList(values));
  9. }
  10. }
  11.  
  12. I'm surprised why the `String[]` cannot be converted to `List<String>` to initialize the `HashSet<String>` with it.
  13.  
  14. I'm getting the build error:
  15.  
  16. > incompatible types: java.util.HashSet<java.lang.String> cannot be converted to java.lang.String[]
  17.  
  18. What's wrong with my assignment?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement