interface ImageReader { fun read(file: File): Bitmap companion object { fun newImageReader(format: String) = when (format) { "jpg" -> JpegReader() "gif" -> GifReader() else -> throw IllegalStateException("Unknown format") } } }val doubleCheeseBurger = Burger(patties = 2, hasCheese = true)| 원칙 | 예시 |
|---|---|
| 반사성 | x.equals(x) 는 항상 true이다 |
| 대칭성 | x.equals(y) = true 이면 y.equals(x) == true이다. |
| 추이성 | x.equals(y) = true, y.equals(z) = true 이면 x.equals(z) 도 true |
| 일관성 | x.equals(y) 의 값은 항상 동일해야 한다. |
| NotNull | x.equals(null) 은 항상 false 이다. |
제네릭
val hitMe = List() // ... val okForObject = List<Any>() val okForAny = List<?>()열거형(Enum) 와 어노테이션
람다
스트림
그 외의 팁