Skip to content

Latest commit

 

History

History
54 lines (48 loc) · 1.76 KB

21_11_26_TIL.md

File metadata and controls

54 lines (48 loc) · 1.76 KB

Generic

  • 변수의 선언이나 메소드의 매개변수를 특정 자료형(String, Integer etc...)이 아닌 다양한 자료형()을 받을 수 있도록 하는 방식
  • 일반적으로 를 사용한다.(T는 Type의 약자이다.)
  • Generic Type으로 선언된 매개변수의 자료형은 Runtimme이 아닌 Compile Time에서 검증한다.
public class GenericPro<T>  {
  private T material;
  
  public void setMaterial(T material) {
    this.material = material;
  }
  
  public T getMaterial()  {
    return material;
  }
}
  • Generic Type 내에서 다른 Class를 상속받을 수 있다.
public class GenericChild<T extends genericParent>  {
  ~~~~
}
  • Generic Type은 여러개를 선언할 수 있다.
public class GenericMul<T, Y, Z> {
  T x;
  Y y;
  Z z;
  
  ~~~
}
  • 메소드 내에서 선언한 Generic 변수는 선언된 메소드 내에서만 유효하다.(지역 변수의 개념과 비슷하다.)
class GenericMethod<T>  {   // class 옆에 선언된 T와
  public static <T, V> double divideNum(T, V) { // Method에서의 T는 다른 Type이다.
    ~~~ 
  }

Collection Framework

  • 프로그래밍에 필요한 자료구조와 알고리즘을 구현한 Class의 집합을 의미한다.
  • 주로 java의 interface를 사용하여 구현한다.
  • java.util package에 구현되어 있다.
  • 하나의 객체를 관리하기 위해 선언된 Interface

Map Interface

  • 쌍으로 이루어진 객체를 관리하기 위해 선언된 Interface
  • (key, value)로 이루어져 있다.

상속 구조

image image