title: Type-safe Builder Library for Scala and Java
body: <p>Below is a type-safe, fluid, builder pattern in Scala as described at <a href="http://www.tikalk.com/java/blog/type-safe-builder-scala-using-type-constraints" rel="nofollow noreferrer">http://www.tikalk.com/java/blog/type-safe-builder-scala-using-type-constraints</a>. It's similar to <a href="https://stackoverflow.com/questions/6337444/builder-library-for-scala-and-java">Builder Library for Scala and Java</a>, but deals specifically with compile-time builder checks. How can this called from Java? Can it be done with a clean API for Scala <em>AND</em> Java given the "scala.Predef$$eq$colon$eq" parameters?</p>
  
  <pre><code>sealed trait TBoolean
  sealed trait TTrue extends TBoolean
  sealed trait TFalse extends TBoolean
  
  class Builder[HasProperty &lt;: TBoolean] private(i: Int) {
    protected def this() = this(-1)
    def withProperty(i: Int)(implicit ev: HasProperty =:= TFalse) = new Builder[TTrue](i)
    def build(implicit ev: HasProperty =:= TTrue) = println(i)
  }
  
  //javap output
      public class Builder extends java.lang.Object implements scala.ScalaObject{
      public Builder withProperty(int, scala.Predef$$eq$colon$eq); //How is this called from Java?
      public void build(scala.Predef$$eq$colon$eq);
      public Builder();
  }
  object Builder {
    def apply() = new Builder[TFalse]
  }
  </code></pre>