I'm trying to define an optional query parameter that will map to a Long
, but will be null
when it is not present in the URL:
GET /foo controller.Foo.index(id: Long ?= null)
... and I essentially want to check if it was passed in or not:
public static Result index(Long id) {
if (id == null) {...}
...
}
However, I'm getting a compilation error:
type mismatch; found : Null(null) required: Long Note that implicit conversions are not applicable because they are ambiguous: both method Long2longNullConflict in class LowPriorityImplicits of type (x: Null)Long and method Long2long in object Predef of type (x: Long)Long are possible conversion functions from Null(null) to Long
Why can't I do this, assigning null
to be a default value for an expected Long
optional query parameter? What's an alternative way to do this?
Option[Long]
thing...? – Gustation