All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xiaoleilu.hutool.lang.Holder Maven / Gradle / Ivy

There is a newer version: 3.3.2
Show newest version
package com.xiaoleilu.hutool.lang;

import com.xiaoleilu.hutool.mutable.MutableObj;

/**
 * 为不可变的对象引用提供一个可变的包装,在java中支持引用传递。
 * @author Looly
 *
 * @param  所持有值类型
 */
public final class Holder extends MutableObj{
	private static final long serialVersionUID = -3119568580130118011L;

	/**
	 * 新建Holder类,持有指定值,当值为空时抛出空指针异常
	 * 
	 * @param  被持有的对象类型
	 * @param value 值,不能为空
	 * @return Holder
	 */
	public static  Holder of(T value) throws NullPointerException{
		if(null == value){
			throw new NullPointerException("Holder can not hold a null value!");
		}
		return new Holder<>(value);
	}
	
	//--------------------------------------------------------------------------- Constructor start
	/**
	 * 构造
	 */
	public Holder() {
		super();
	}
	
	/**
	 * 构造
	 * @param value 被包装的对象
	 */
	public Holder(T value) {
		super(value);
	}
	//--------------------------------------------------------------------------- Constructor end
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy