mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpiutil] Add WPICleaner and an example how to use it (#4850)
This commit is contained in:
28
wpiutil/src/main/java/edu/wpi/first/util/WPICleaner.java
Normal file
28
wpiutil/src/main/java/edu/wpi/first/util/WPICleaner.java
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.util;
|
||||
|
||||
import java.lang.ref.Cleaner;
|
||||
import java.lang.ref.Cleaner.Cleanable;
|
||||
|
||||
/** Cleaner object for WPILib objects. */
|
||||
public final class WPICleaner {
|
||||
private WPICleaner() {
|
||||
throw new UnsupportedOperationException("This is a utility class!");
|
||||
}
|
||||
|
||||
private static final Cleaner instance = Cleaner.create();
|
||||
|
||||
/**
|
||||
* Register an object with the cleaner.
|
||||
*
|
||||
* @param object The object to register.
|
||||
* @param runnable The runnable to call on cleanup.
|
||||
* @return The registered Cleanable.
|
||||
*/
|
||||
public static Cleanable register(Object object, Runnable runnable) {
|
||||
return instance.register(object, runnable);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user