# Primitive, Reference, Generic

## Primitive Type vs Reference Type (Using Wrapper Class)

* Primitive Type 의 속도가 월등히 빠르다.
* Generic 에는 Primitive Type 사용이 불가하다.

## Generic 에서의 Primitive Type vs Reference Type

### Primitive Type Array

```
ArrayDeque<Integer> deque1 = new ArrayDeque<>();
deque1.add("qwer");
deque1.add(1); 
deque1.add('b'); 

for (Object o : deque1){
    int x = (int)o; // String -> int 변환에서 에러가 발생한다.
    System.out.println(x);
}
```

* 런타임 에러가 발생한다.

### Generic using Reference Type

```
ArrayDeque<Integer> deque2 = new ArrayDeque<>();
deque2.add("qwer"); // Syntax Error
deque2.add(1); // CORRECT
deque2.add('b'); // Syntax Error

for (Object o : deque1){
    int x = (int)o; 
    System.out.println(x);
}
```

* Syntax 에러를 통해서 컴파일 이전에 에러가 있음을 알 수 있다.
* 프로그램 실행 자체가 불가능하다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://seungyeon-kang.gitbook.io/yeons-frame/study-1/algorithm/intro/1.-data-types-primitive-and-reference-and-generic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
