implicit class And[A](a: A) {
def and(f: A => Unit): A = {
f(a); a
}
}
这样你就可以
val button = (new JButton("Press me!")
and (_ setForeground Color.red)
and (_ setFont new Font(null, Font.PLAIN, 12)))
val win = (new JFrame("Hello!")
and (_ add button)
and (_ pack())
and (_ setDefaultCloseOperation JFrame.EXIT_ON_CLOSE)
and (_ setVisible(true)))