我从Picasso的源代码中复制了以下类。实际上,我要求Picasso不要缓存图像。
有人可以解释一下这两行吗?
NO_CACHE(1 << 0), NO_STORE(1 << 1);
我知道位运算符,我只想知道为什么我们需要它们在这里?
他们还抑制了PointlessBitwiseExpression警告。
有人可以解释一下这两行吗?
NO_CACHE(1 << 0), NO_STORE(1 << 1);
我知道位运算符,我只想知道为什么我们需要它们在这里?
他们还抑制了PointlessBitwiseExpression警告。
/** Designates the policy to use when dealing with memory cache. */
@SuppressWarnings("PointlessBitwiseExpression")
public enum MemoryPolicy {
/** Skips memory cache lookup when processing a request. */
NO_CACHE(1 << 0),
/**
* Skips storing the final result into memory cache. Useful for one-off requests
* to avoid evicting other bitmaps from the cache.
*/
NO_STORE(1 << 1);
static boolean shouldReadFromMemoryCache(int memoryPolicy) {
return (memoryPolicy & MemoryPolicy.NO_CACHE.index) == 0;
}
static boolean shouldWriteToMemoryCache(int memoryPolicy) {
return (memoryPolicy & MemoryPolicy.NO_STORE.index) == 0;
}
final int index;
private MemoryPolicy(int index) {
this.index = index;
}
}
NO_CACHE
的index
值为1
,NO_STORE
的index
值为2
。 - QBrute