please see the below code. This line is marked as incorrect by Eclipse:
var map = Map[MyEnum,Point]()
I am trying to do the scala equivalent of Java:
private enum Letters{ A,B,C}
private Map<Letters,Integer> thing= new HashMap<Letters,Integer> ();
And this is the file/context in which it is written.
class Point(var x:Int = 0, var y:Int = 0, var hasBeenSet:Boolean = false){
}
object MyEnum extends Enumeration{
MyEnum = Value
val UL,U,UR,L,R,DL,D,DR = Value
}
object MyEnumHolder {
var map = Map[MyEnum,Point]()
MyEnum.values.foreach(x => (map + (x -> new Point()) )
}
I am trying to initialize an instance of the map with each value of the enum mapped to an empty point (that’s what is going on in the for each loop).
EDIT: Had to edit because I messed some things up editing the pasted code, but it should be valid now
or I prefer
edit: To give a little explanation of what this means, in the enumeration
Valueis the name of both a type and a method.type MyEnum = Valueis basically just declaring an alias for theValuetype, and the next lineval UL, U... = Valueis calling the method to generate the enums, each of which has typeMyEnum.Value. So when declaring the map, you have to refer to this type in order for the key to store enums. You could also useMyEnum.MyEnum, but the reason you declare the type alias in the first place is so you can import it into scope and be able to refer to it just asMyEnum.