Question

In my REST API Controller, I receive a list of strings, if the input list is empty i should return bad request.
The problem is the input is empty, the list contains no items, but the check:

if(productIdsList.isEmpty)  

Return false.

How could that be ??

enter image description here

Was it helpful?

Solution

It is not empty, it contains an empty String.

Seems like Eclipse shows and empty String as an empty value (and not as "" in Scala REPL) and this is confusing. Try debugging this, it looks exactly the same.

object A extends Application {
  val a = List("")
  //any other code here
}

The empty list is Nil and it looks exactly like productIdsList.tl in your debug view

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top