此代码用于演示双重检查锁定反模式:
@NotThreadSafe
public class DoubleCheckedLocking {
private static Resource resource;
public static Resource getInstance() {
if (resource == null) {
synchronized (DoubleCheckedLocking.class) {
if (resource == null)
res
当我使用RecyclerView刷新时,我不想隐藏SwipeRefreshLayout。因此,我在我的ViewState类中引入了重载状态:
sealed class Resource<out T> {
class Loading<out T> : Resource<T>()
class Reloading<out T> : Resource<T>()
data class Success<out T>(val data: T?) : Resource<T>()
data cla
这是我的简单unique_ptr实现。任何可以改进或应该增加的东西?
#include
template
class unique_ptr
{
private:
T * ptr_resource = nullptr;
public:
// Safely constructs resource. Operator new is called by the user. Once constructed the unique_ptr will own the resource.
// std::move is used because it is used to indi