scala type alias to java enum does not work?

Viewed 119

Scala type alias to java class works fine, i.e.

type JavaDate = org.joda.time.LocalDate

val date = new JavaDate(2019, 6, 20)
println(date)

But type alias to java enum does not work?

val m1 = java.time.Month.JANUARY
println(m1)

type JavaMonth = java.time.Month

val m2 = JavaMonth.FEBRUARY
println(m2)

Error: not found: value JavaMonth: val m2 = JavaMonth.FEBRUARY

How can I use alias to java enum? Thanks!

1 Answers

Consider using import renaming instead of type aliases like so:

import java.time.{Month => JavaMonth}
val m2 = JavaMonth.FEBRUARY

Type alias might be more appropriate for simplifying more complex types like

type Response = Future[Either[Error, Int]]
Related