Question

Hello I am fairly new to Scala.
I want to learn Scala because:

  1. To get rid of boiler plate code from Java.
  2. Play with different paradigms.
  3. Just for fun of learning new things

I am following a tutorial on plays website.

Here is the tutorial code:

Player.create(Player(Id(1), "bob@gmail.com", "secret", "Bob", false)) 
Post.create(Post(NotAssigned, "My 1st post", "Hello world", new Date, 1))

To get deeper knowledge I played around and modified the examples.
I decided not to give the Player a predefined ID but let MySql assign it.
In MySql I have defined the Player id as an int but Post id as an long. // I will change this later but for this example it is important.

But what shocked me is the way I did it, look at the second row. This is not the elegant at all.

val player = Player.create(Player(NotAssigned, "bob@gmail.com", "secret", "Bob", false)) 
val id = player.get.id.get.get.asInstanceOf[Number].intValue()
Post.create(Post(NotAssigned, "My 1st post", "Hello world", new Date, id)

Now to my question how do I get the Id as an int from the created player in a less absurd way?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top