Advertisement
Guest User

Untitled

a guest
Oct 16th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.50 KB | None | 0 0
  1. //Document2.scala
  2. object Title // This object is used an an argument for a fluent interface
  3.  
  4. class Document {
  5.   private var title = ""
  6.   private var useNextArgAs: Any = null
  7.   def set(obj: Title.type): this.type = { useNextArgAs = obj; this }
  8.   def to(arg: String) = if (useNextArgAs == Title) title = arg;
  9.   override def toString = getClass.getName + "[title=" + title + "]"
  10. }
  11.  
  12. object Main extends App {
  13.   val book = new Document
  14.   book set Title to "Scala for the Impatient"
  15.   println(book)
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement