Initialize caches inline
Fixes #59
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
index 7cd0e57..5356450 100644
--- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
+++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java
@@ -50,8 +50,9 @@
Strong
}
- @Nullable private static Map<String, LottieComposition> strongRefCache;
- @Nullable private static Map<String, WeakReference<LottieComposition>> weakRefCache;
+ private static final Map<String, LottieComposition> strongRefCache = new HashMap<>();
+ private static final Map<String, WeakReference<LottieComposition>> weakRefCache =
+ new HashMap<>();
private final LottieComposition.OnCompositionLoadedListener loadedListener =
new LottieComposition.OnCompositionLoadedListener() {
@@ -216,14 +217,8 @@
@Override
public void onCompositionLoaded(LottieComposition composition) {
if (cacheStrategy == CacheStrategy.Strong) {
- if (strongRefCache == null) {
- strongRefCache = new HashMap<>();
- }
strongRefCache.put(animationName, composition);
} else if (cacheStrategy == CacheStrategy.Weak) {
- if (weakRefCache == null) {
- weakRefCache = new HashMap<>();
- }
weakRefCache.put(animationName, new WeakReference<>(composition));
}