foreach and Enumeration

后端 未结 1 697
天命终不由人
天命终不由人 2021-01-18 08:46

I\'m try to learn some Scala reading Programming Scala, by Dean Wampler.

I\'m trying to replicate a code snippet about Enumeration

obje         


        
1条回答
  •  生来不讨喜
    2021-01-18 09:04

    You need to use .values:

    for (breed <- Breed.values) println(breed.id + "\t" + breed)
    

    And why not make it a bit more scala-y

    Breed.values.foreach(breed => println(breed.id + "\t" + breed));
    

    0 讨论(0)
提交回复
热议问题