
ru.progrm_jarvis.javacommons.object.ReferenceUtil Maven / Gradle / Ivy
package ru.progrm_jarvis.javacommons.object;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.ref.WeakReference;
/**
* Utility for reference-related features.
*/
@UtilityClass
public class ReferenceUtil {
/**
* Singleton of {@link WeakReference} to {@code null}
*/
private final @NotNull WeakReference<@Nullable ?> WEAK_REFERENCE_TO_NULL = new WeakReference<>(null);
/**
* Gets a {@link WeakReference} stub singleton.
*
* @param type of value intended to be referenced
* @return {@link WeakReference} stub singleton
*/
@SuppressWarnings("unchecked")
public static <@Nullable T> @NotNull WeakReference weakReferenceToNull() {
return (WeakReference) WEAK_REFERENCE_TO_NULL;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy