Created
October 23, 2014 20:42
-
-
Save joescii/552efbcfd3d43eaad4ba to your computer and use it in GitHub Desktop.
The good, bad, and ugly of implicits with +
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 com.joescii | |
import org.scalatest.{ShouldMatchers, FlatSpecLike} | |
/** | |
* Created by jbarnes on 10/23/2014. | |
*/ | |
class ImplicitSpecs extends FlatSpecLike with ShouldMatchers { | |
"Scala implicits" should "act like their java counterparts" in { | |
val java = new MyJavaClass | |
java.a should equal (1 + "1") | |
java.b should equal (1 + 1 + "1") | |
java.c should equal ("1" + 1 + 1) | |
java.d should equal (1 + "1" + 1) | |
} | |
} |
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 com.joescii; | |
/** | |
* Created by jbarnes on 1/24/14. | |
*/ | |
public class MyJavaClass { | |
public String a = 1 + "1"; | |
public String b = 1 + 1 + "1"; | |
public String c = "1" + 1 + 1; | |
public String d = 1 + "1" + 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for taking the time to do this - appreciate it!
The problem is exactly that Scala values (consistency with Java) more than (strict strong-typing) :)