Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
Scala /
conversions
scala> val x = 5 x: Int = 5 scala> x.toString res5: String = 5 // it's not shown in quotes but it's a String scala> ""+x res6: String = 5 scala> val s = "2015" s: String = 2015 scala> s.toInt res7: Int = 2015 scala> "scala".toInt java.lang.NumberFormatException: For input string: "scala" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.parseInt(Integer.java:615) at scala.collection.immutable.StringLike$class.toInt(StringLike.scala:272) at scala.collection.immutable.StringOps.toInt(StringOps.scala:30) ... 33 elided
"Omit empty parenthesis, only be used when the method in question has no side-effects (purely-functional). In other words, it would be acceptable to omit parentheses when calling queue.size, but not when calling println(). Religiously observing this convention will dramatically improve code readability and will make it much easier to understand at a glance the most basic operation of any given method. Resist the urge to omit parentheses simply to save two characters!" So, if the function returns some value but doesn't change the object who called it, then you can omit the parentheses. |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |