Created
November 22, 2017 10:00
-
-
Save JavierCane/57985c072026b36bcce0f3888164c2f5 to your computer and use it in GitHub Desktop.
Scala companion object example for the CodelyTV Pro Scala course π https://pro.codely.tv/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tv.codely.scala_intro_examples.lesson_09_oop | |
import scala.util.Random | |
object NumberWithCompanionObject { | |
def apply(value: String): NumberWithCompanionObject = NumberWithCompanionObject(value = value.toInt) | |
def random: NumberWithCompanionObject = NumberWithCompanionObject(value = Random.nextInt()) | |
} | |
final case class NumberWithCompanionObject(value: Int) { | |
val plusOne: NumberWithCompanionObject = copy(value = value + 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment