Type Class

HEP·2022년 12월 27일
0

Type Class

Type t1 = Account.class;
Type t2 = Type.forName('Account');
System.assert(t1.equals(t2));

Type.forName의 활용

System.Type objType = Type.forName('Animal');
Animal target = (Animal) objType.newInstance();
System.debug('***target: ' + target); // 기본 생성자 실행 + 전역 변수 값 출력

정리

  1. Type.forName('class이름').newInstance(); 사용시
    -> 해당 클래스의 default constructor가 실행된다.

  1. 메서드를 실행시키기 위해서는
    a) Callable interface를 상속받아 call method 구현하거나
    b) Type.forName('class이름').newInstance().method이름()
profile
셀포합니다

0개의 댓글