Skip to content

Instantly share code, notes, and snippets.

@joescii
Created October 23, 2014 20:42
Show Gist options
  • Save joescii/552efbcfd3d43eaad4ba to your computer and use it in GitHub Desktop.
Save joescii/552efbcfd3d43eaad4ba to your computer and use it in GitHub Desktop.
The good, bad, and ugly of implicits with +
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)
}
}
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;
}
@johnazariah
Copy link

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) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment