diff --git a/puzzlers/pzzlr-case-defaults.html b/puzzlers/pzzlr-case-defaults.html new file mode 100644 index 0000000..315c0d1 --- /dev/null +++ b/puzzlers/pzzlr-case-defaults.html @@ -0,0 +1,86 @@ +

Well, In This Case...

+ + + + + + + + + + + + + + + +
Contributed byAndrew Phillips
SourceDidier Dupont
First tested with Scala version2.11.2
+
+

What is the result of executing the following code?

+
+case class Toy(squeezeMsg: String = this.toString) {
+  override def toString = squeezeMsg
+}
+println(Toy("My name is Fido!") == new Toy("My name is Fido!"))
+println(Toy() == new Toy())
+
+
    +
  1. Fails to compile
  2. +
  3. Prints: +
    +true
    +false
    +
    +
  4. +
  5. Prints: +
    +true
    +true
    +
    +
  6. +
  7. The first statement prints: +
    +true
    +
    +and the second throws a runtime exception +
  8. +
+
+ + \ No newline at end of file