I've been staring at the screen the last 5 minutes and can't seem to figure out what I'm doing wrong:
class Example {
private final Set<String> values;
public Example(String... values) {
values = new HashSet<String>(Arrays.asList(values));
}
}
I'm surprised why the String[] cannot be converted to List<String> to initialize the HashSet<String> with it.
I'm getting the build error:
incompatible types: java.util.HashSet<java.lang.String> cannot be converted to java.lang.String[]
What's wrong with my assignment?
valuesparameter inside of your constructor is shadowing the class fieldvalues.this.values, or by changing the name of the constructor argument.