I don’t like how the code below looks and I’d like to know how I could do it using the ternary operator:
if (isIndexed) {
Files.move(source, destination);
}
else {
Files.move(source, destination, StandardCopyOption.REPLACE_EXISTING);
}
I’m expecting something that looks like:
Files.move(source, destination, isIndexed ? xxxx : StandardCopyOption.REPLACE_EXISTING);
If there were some kind of “default” copy option I could use, I think that would be what I’m looking for. But the enum for StandardCopyOption doesn’t have a “NONE” option.
So I’m probably missing something. What is it?
It’s a varargs argument, so you could just set an empty array by
new StandardCopyOption[0].You only need to make the other hand of the condition an array too. You could refactor it to two (local) constants to improve readability.