The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 |
From: James Ong <yanlile...@gmail.com>
Date: Thu, 12 Jul 2012 06:24:50 -0700 (PDT)
Local: Thurs, Jul 12 2012 9:24 am
Subject: Scala basic calculation
I found this SO question only explain the code example for Java, tried Scala turn out a little different: http://stackoverflow.com/questions/10024880/calculation-in-play-2-0-f... What wrong with the getSum code? type mismatch; found : Int required: String object Application extends Controller { def index = Action { Ok(views.html.index("1","2",Application.getSum("1","2"))) //<- Error type mismatch } def getSum(a: String,b: String):Int = Action { val c = a.toInt + b.toInt; } c
}
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
From: Marcel Klemenz <maklem...@gmail.com>
Date: Thu, 12 Jul 2012 06:42:46 -0700 (PDT)
Local: Thurs, Jul 12 2012 9:42 am
Subject: Re: Scala basic calculation
Or do you try to pass String String Int of your template requires String String String? would make more sense. Am Donnerstag, 12. Juli 2012 15:24:50 UTC+2 schrieb James Ong:
> I found this SO question only explain the code example for Java, tried > Scala turn out a little different: > http://stackoverflow.com/questions/10024880/calculation-in-play-2-0-f... > What wrong with the getSum code? > type mismatch; found : Int required: String > object Application extends Controller { > def index = Action { > Ok(views.html.index("1","2",Application.getSum("1","2"))) //<- Error > type mismatch > } > def getSum(a: String,b: String):Int = Action { > val c = a.toInt + b.toInt; > } c > }
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
From: James Ong <yanlile...@gmail.com>
Date: Thu, 12 Jul 2012 06:44:38 -0700 (PDT)
Local: Thurs, Jul 12 2012 9:44 am
Subject: Re: Scala basic calculation
Oh, I spotted my index template is a String, So rewrite as getSum("1","2").*toString*) Will solve the type issue.
On Thursday, 12 July 2012 21:24:50 UTC+8, James Ong wrote: > I found this SO question only explain the code example for Java, tried > Scala turn out a little different: > http://stackoverflow.com/questions/10024880/calculation-in-play-2-0-f... > What wrong with the getSum code? > type mismatch; found : Int required: String > object Application extends Controller { > def index = Action { > Ok(views.html.index("1","2",Application.getSum("1","2"))) //<- Error > type mismatch > } > def getSum(a: String,b: String):Int = Action { > val c = a.toInt + b.toInt; > } c > }
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
From: James Ong <yanlile...@gmail.com>
Date: Thu, 12 Jul 2012 06:50:27 -0700 (PDT)
Local: Thurs, Jul 12 2012 9:50 am
Subject: Re: Scala basic calculation
For the quick working example for Scala, any tips to optimize the code below will be appreciated! object Application extends Controller { def index = Action { Ok(views.html.index("1","2",getSum("1","2").toString)) } var c:Int = 0; def getSum(a: String,b: String):String = { c = a.toInt + b.toInt c.toString ///return c as String }
}
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
From: Andrew Conner <att...@gmail.com>
Date: Thu, 12 Jul 2012 08:54:40 -0700 (PDT)
Local: Thurs, Jul 12 2012 11:54 am
Subject: Re: Scala basic calculation
Why are you using Strings for everything? I would make getSum be: getSum(a: Int, b: Int) = a+b and then change your view to take Ints.
On Thursday, July 12, 2012 9:50:27 AM UTC-4, James Ong wrote: > For the quick working example for Scala, any tips to optimize the code > below will be appreciated! > object Application extends Controller { > def index = Action { > Ok(views.html.index("1","2",getSum("1","2").toString)) > } > var c:Int = 0; > def getSum(a: String,b: String):String = { > c = a.toInt + b.toInt > c.toString ///return c as String > } > }
You must Sign in before you can post messages.
You do not have the permission required to post.
|
|
|