본문 바로가기

개발일지(일간)

22년 12월 01일 인터페이스와 업캐스팅

인터페이스의 자동타입변환에 대해서 공부했다.

  • 상속 또는 인터페이스의 자동 타입 변환(Promotion)
  • 인터페이스 변수 = 구현객체; ← 자동 타입 변환
  • Interface clazz = new InterfaceImplementClass();
  • Promotion Memory 구조 보기

  • 상위 인터페이스, 클래스, 추상 클래스로 Upcasting 가능
  • → 모든 클래스는 extends Object 가 생략되어있다.
  • → 모든 클래스는 Object로 Upcasting 가능

그림에 대해서 나름 해석해봤는데

Service의 구현객체 new DefaultService

DefaultService의 구현객체 new DefaultServiceExtend();

Service의 구현객체 (DefaultService(생략))의 구현객체 new DefaultServiceExtend();(업캐스팅)

인것같다.