Reduce compiler warnings
This commit is contained in:
parent
3ed3ec85a3
commit
4d63091bdc
|
@ -67,7 +67,7 @@ public abstract class AtomicInitializer<T> extends AbstractConcurrentInitializer
|
||||||
private static final Object NO_INIT = new Object();
|
private static final Object NO_INIT = new Object();
|
||||||
|
|
||||||
/** Holds the reference to the managed object. */
|
/** Holds the reference to the managed object. */
|
||||||
private final AtomicReference<T> reference = new AtomicReference<>((T) NO_INIT);
|
private final AtomicReference<T> reference = new AtomicReference<>(getNoInit());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the object managed by this initializer. The object is created if
|
* Returns the object managed by this initializer. The object is created if
|
||||||
|
@ -82,9 +82,9 @@ public abstract class AtomicInitializer<T> extends AbstractConcurrentInitializer
|
||||||
public T get() throws ConcurrentException {
|
public T get() throws ConcurrentException {
|
||||||
T result = reference.get();
|
T result = reference.get();
|
||||||
|
|
||||||
if (result == (T) NO_INIT) {
|
if (result == getNoInit()) {
|
||||||
result = initialize();
|
result = initialize();
|
||||||
if (!reference.compareAndSet((T) NO_INIT, result)) {
|
if (!reference.compareAndSet(getNoInit(), result)) {
|
||||||
// another thread has initialized the reference
|
// another thread has initialized the reference
|
||||||
result = reference.get();
|
result = reference.get();
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,12 @@ public abstract class AtomicInitializer<T> extends AbstractConcurrentInitializer
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the internal no-init object cast for this instance. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private T getNoInit() {
|
||||||
|
return (T) NO_INIT;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether this instance is initialized. Once initialized, always returns true.
|
* Tests whether this instance is initialized. Once initialized, always returns true.
|
||||||
*
|
*
|
||||||
|
|
|
@ -59,7 +59,7 @@ public abstract class AtomicSafeInitializer<T> extends AbstractConcurrentInitial
|
||||||
private final AtomicReference<AtomicSafeInitializer<T>> factory = new AtomicReference<>();
|
private final AtomicReference<AtomicSafeInitializer<T>> factory = new AtomicReference<>();
|
||||||
|
|
||||||
/** Holds the reference to the managed object. */
|
/** Holds the reference to the managed object. */
|
||||||
private final AtomicReference<T> reference = new AtomicReference<>((T) NO_INIT);
|
private final AtomicReference<T> reference = new AtomicReference<>(getNoInit());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets (and initialize, if not initialized yet) the required object
|
* Gets (and initialize, if not initialized yet) the required object
|
||||||
|
@ -72,7 +72,7 @@ public abstract class AtomicSafeInitializer<T> extends AbstractConcurrentInitial
|
||||||
public final T get() throws ConcurrentException {
|
public final T get() throws ConcurrentException {
|
||||||
T result;
|
T result;
|
||||||
|
|
||||||
while ((result = reference.get()) == (T) NO_INIT) {
|
while ((result = reference.get()) == getNoInit()) {
|
||||||
if (factory.compareAndSet(null, this)) {
|
if (factory.compareAndSet(null, this)) {
|
||||||
reference.set(initialize());
|
reference.set(initialize());
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,12 @@ public abstract class AtomicSafeInitializer<T> extends AbstractConcurrentInitial
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Gets the internal no-init object cast for this instance. */
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private T getNoInit() {
|
||||||
|
return (T) NO_INIT;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether this instance is initialized. Once initialized, always returns true.
|
* Tests whether this instance is initialized. Once initialized, always returns true.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue