3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

既存クラスにメソッド追加

Posted at

##例1: Doubleクラスに単位変換メソッドを追加

implicit def convert(d:Double) = new {
  //ミリ→ポイント変換
  def mmToPoint = {d * 2.835}
  //ポイント→ミリ変換
  def pointToMm = {d * 0.353}
}


val originalMm = 100d
val point = originalMm.mmToPoint

val originalPoint = 100d
val mm = originalPoint.pointToMm

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?