-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Week1][입문편] 14강 코틀린에서 다양한 클래스를 다루는 방법 (#2)
- Loading branch information
Showing
6 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package lec14 | ||
|
||
import lec14.Country.* | ||
|
||
fun handleCountry(country: Country) { | ||
when (country) { | ||
KOREA -> TODO() | ||
AMERICA -> TODO() | ||
} | ||
} | ||
|
||
enum class Country( | ||
private val code: String | ||
) { | ||
KOREA("KO"), | ||
AMERICA("US") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package lec14; | ||
|
||
public enum JavaCountry { | ||
|
||
KOREA("KO"), | ||
AMERICA("US"), | ||
|
||
; | ||
|
||
private final String code; | ||
|
||
JavaCountry(final String code) { | ||
this.code = code; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
private static void handleCountry(JavaCountry country) { | ||
if (country == JavaCountry.KOREA) { | ||
// 로직 처리 | ||
} | ||
|
||
if (country == JavaCountry.AMERICA) { | ||
// 로직 처리 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package lec14; | ||
|
||
import java.util.Objects; | ||
|
||
public class JavaPersonDto { | ||
|
||
private final String name; | ||
private final int age; | ||
|
||
public JavaPersonDto(final String name, final int age) { | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
JavaPersonDto that = (JavaPersonDto) o; | ||
return getAge() == that.getAge() && Objects.equals(getName(), that.getName()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getName(), getAge()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JavaPersonDto{" + | ||
"name='" + name + '\'' + | ||
", age=" + age + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package lec14 | ||
|
||
fun main() { | ||
val dto1 = PersonDto("임준형", 100) | ||
val dto2 = PersonDto("임준형", 200) | ||
val dto3 = PersonDto("임준형", 200) | ||
println(dto1 == dto2) | ||
println(dto2 == dto3) | ||
println(dto3) | ||
} | ||
|
||
data class PersonDto( | ||
val name: String, | ||
val age: Int | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters