0

Java code

objRefs = objRefs.stream().filter(objRef -> DataUtil.isNotEmpty(objRef)).collect(Collectors.toCollection(LinkedHashSet::new));

How to convert it to scala? Following code compile error

objRefs = objRefs.stream().filter(objRef => DataUtil.isNotEmpty(objRef)).collect(Collectors.toCollection(LinkedHashSet::new));

1 Answer 1

2

LinkedHashSet::new is not valid scala. Do you mean to call the constructor of LinkedHashSet? If so, use new LinkedHashSet(_)

The solution you've chosen is translating java to scala. If you do that, there is little value in using scala at all, and you might as well use java.

A more idiomatic solution would be

objRefs.stream().filter(DataUtil.isNotEmpty).asScala(Set)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.