여기서 객체 소멸자란 생성자와 정반대의 개념으로, 객체가 소멸될떄(GC될때) 자동으로 호출되는 함수이다.
Java 9에서부터는 finalizer를 사용 자제해야 할 API로 지정하고, cleaner를 그 대안으로 소개하였다. 하지만 책에서는 cleaner또는 finalizer의 사용을 피하라고 얘기하고 있다,.그렇다면 finalizer와 cleaner는 왜 사용하면 안될까?
/** * A converter converts a source object of type {@code S} to a target of type {@code T}. */ @FunctionalInterface publicinterfaceConverter<S, T> {
/** * Convert the source object of type {@code S} to target type {@code T}. * @param source the source object to convert, which must be an instance of {@code S} (never {@code null}) * @return the converted object, which must be an instance of {@code T} (potentially {@code null}) * @throws IllegalArgumentException if the source cannot be converted to the desired target type */ @Nullable T convert(S source);