Using type aliases to Java enums

Posted by oxbow_lakes on Stack Overflow See other posts from Stack Overflow or by oxbow_lakes
Published on 2009-10-22T09:13:16Z Indexed on 2010/04/01 15:53 UTC
Read the original article Hit count: 305

Filed under:
|
|

I would like to achieve something similar to how scala defines Map as both a predefined type and object. In Predef:

type Map[A, +B] = collection.immutable.Map[A, B]
val Map = collection.immutable.Map //object Map

However, I'd like to do this using Java enums (from a shared library). So for example, I'd have some global alias:

type Country = my.bespoke.enum.Country
val Country = my.bespok.enum.Country //compile error: "object Country is not a value"

The reason for this is that I'd like to be able to use code like:

if (city.getCountry == Country.UNITED_KINGDOM) //or...
if (city.getCountry == UNITED_KINGDOM)

Howver, this not possible whilst importing my type alias at the same time. Note: this code would work just fine if I had not declared a predefined type and imported it! Is there some syntax I can use here to achieve this?

© Stack Overflow or respective owner

Related posts about scala

Related posts about enums