Skip to content

Commit

Permalink
Post: Object-related 초안 #1
Browse files Browse the repository at this point in the history
Object를 활용한 예시들..
  • Loading branch information
dtoecho committed Jun 21, 2024
1 parent 39042dc commit 27c5b46
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/content/blog/04-Object-related/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Object
date: 2024-06-21
description: Object 활용
---
---

## 1 . instanceof
---

```java
private static void method(Object obj) {
if (obj instanceof InstanceType instance) {
instance.method();
}
}
```

- 여기서 InstanceType은 검사하려는 특정 타입을, instance는 그 타입으로 다운캐스팅 된 객체를 참조하는 변수를 나타내고, 이 패턴은 특히 타입이 여러 가지일 수 있는 매개변수를 처리할 때 많이 사용.
- 타입 검사와 다운캐스팅을 한 줄의 코드로 수행할 수 있음.

0 comments on commit 27c5b46

Please sign in to comment.