• Boolean源码比较简单。

     public final class Boolean implements java.io.Serializable,
    Comparable<Boolean>
    {
    /**
    * The {@code Boolean} object corresponding to the primitive
    * value {@code true}.
    */
    public static final Boolean TRUE = new Boolean(true); /**
    * The {@code Boolean} object corresponding to the primitive
    * value {@code false}.
    */
    public static final Boolean FALSE = new Boolean(false); /**
    * The Class object representing the primitive type boolean.
    *
    * @since JDK1.1
    */
    @SuppressWarnings("unchecked")
    public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean"); /**
    * The value of the Boolean.
    *
    * @serial
    */
    private final boolean value; /** use serialVersionUID from JDK 1.0.2 for interoperability */
    private static final long serialVersionUID = -3665804199014368530L; /**
    * Allocates a {@code Boolean} object representing the
    * {@code value} argument.
    *
    * <p><b>Note: It is rarely appropriate to use this constructor.
    * Unless a <i>new</i> instance is required, the static factory
    * {@link #valueOf(boolean)} is generally a better choice. It is
    * likely to yield significantly better space and time performance.</b>
    *
    * @param value the value of the {@code Boolean}.
    */
    public Boolean(boolean value) {
    this.value = value;
    } /**
    * Allocates a {@code Boolean} object representing the value
    * {@code true} if the string argument is not {@code null}
    * and is equal, ignoring case, to the string {@code "true"}.
    * Otherwise, allocate a {@code Boolean} object representing the
    * value {@code false}. Examples:<p>
    * {@code new Boolean("True")} produces a {@code Boolean} object
    * that represents {@code true}.<br>
    * {@code new Boolean("yes")} produces a {@code Boolean} object
    * that represents {@code false}.
    *
    * @param s the string to be converted to a {@code Boolean}.
    */
    public Boolean(String s) {
    this(parseBoolean(s));
    } /**
    * Parses the string argument as a boolean. The {@code boolean}
    * returned represents the value {@code true} if the string argument
    * is not {@code null} and is equal, ignoring case, to the string
    * {@code "true"}. <p>
    * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
    * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
    *
    * @param s the {@code String} containing the boolean
    * representation to be parsed
    * @return the boolean represented by the string argument
    * @since 1.5
    */
    public static boolean parseBoolean(String s) {
    return ((s != null) && s.equalsIgnoreCase("true"));
    } /**
    * Returns the value of this {@code Boolean} object as a boolean
    * primitive.
    *
    * @return the primitive {@code boolean} value of this object.
    */
    public boolean booleanValue() {
    return value;
    } /**
    * Returns a {@code Boolean} instance representing the specified
    * {@code boolean} value. If the specified {@code boolean} value
    * is {@code true}, this method returns {@code Boolean.TRUE};
    * if it is {@code false}, this method returns {@code Boolean.FALSE}.
    * If a new {@code Boolean} instance is not required, this method
    * should generally be used in preference to the constructor
    * {@link #Boolean(boolean)}, as this method is likely to yield
    * significantly better space and time performance.
    *
    * @param b a boolean value.
    * @return a {@code Boolean} instance representing {@code b}.
    * @since 1.4
    */
    public static Boolean valueOf(boolean b) {
    return (b ? TRUE : FALSE);
    } /**
    * Returns a {@code Boolean} with a value represented by the
    * specified string. The {@code Boolean} returned represents a
    * true value if the string argument is not {@code null}
    * and is equal, ignoring case, to the string {@code "true"}.
    *
    * @param s a string.
    * @return the {@code Boolean} value represented by the string.
    */
    public static Boolean valueOf(String s) {
    return parseBoolean(s) ? TRUE : FALSE;
    } /**
    * Returns a {@code String} object representing the specified
    * boolean. If the specified boolean is {@code true}, then
    * the string {@code "true"} will be returned, otherwise the
    * string {@code "false"} will be returned.
    *
    * @param b the boolean to be converted
    * @return the string representation of the specified {@code boolean}
    * @since 1.4
    */
    public static String toString(boolean b) {
    return b ? "true" : "false";
    } /**
    * Returns a {@code String} object representing this Boolean's
    * value. If this object represents the value {@code true},
    * a string equal to {@code "true"} is returned. Otherwise, a
    * string equal to {@code "false"} is returned.
    *
    * @return a string representation of this object.
    */
    public String toString() {
    return value ? "true" : "false";
    } /**
    * Returns a hash code for this {@code Boolean} object.
    *
    * @return the integer {@code 1231} if this object represents
    * {@code true}; returns the integer {@code 1237} if this
    * object represents {@code false}.
    */
    @Override
    public int hashCode() {
    return Boolean.hashCode(value);
    } /**
    * Returns a hash code for a {@code boolean} value; compatible with
    * {@code Boolean.hashCode()}.
    *
    * @param value the value to hash
    * @return a hash code value for a {@code boolean} value.
    * @since 1.8
    */
    public static int hashCode(boolean value) {
    return value ? 1231 : 1237;
    } /**
    * Returns {@code true} if and only if the argument is not
    * {@code null} and is a {@code Boolean} object that
    * represents the same {@code boolean} value as this object.
    *
    * @param obj the object to compare with.
    * @return {@code true} if the Boolean objects represent the
    * same value; {@code false} otherwise.
    */
    public boolean equals(Object obj) {
    if (obj instanceof Boolean) {
    return value == ((Boolean)obj).booleanValue();
    }
    return false;
    } /**
    * Returns {@code true} if and only if the system property
    * named by the argument exists and is equal to the string
    * {@code "true"}. (Beginning with version 1.0.2 of the
    * Java<small><sup>TM</sup></small> platform, the test of
    * this string is case insensitive.) A system property is accessible
    * through {@code getProperty}, a method defined by the
    * {@code System} class.
    * <p>
    * If there is no property with the specified name, or if the specified
    * name is empty or null, then {@code false} is returned.
    *
    * @param name the system property name.
    * @return the {@code boolean} value of the system property.
    * @throws SecurityException for the same reasons as
    * {@link System#getProperty(String) System.getProperty}
    * @see java.lang.System#getProperty(java.lang.String)
    * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
    */
    public static boolean getBoolean(String name) {
    boolean result = false;
    try {
    result = parseBoolean(System.getProperty(name));
    } catch (IllegalArgumentException | NullPointerException e) {
    }
    return result;
    } /**
    * Compares this {@code Boolean} instance with another.
    *
    * @param b the {@code Boolean} instance to be compared
    * @return zero if this object represents the same boolean value as the
    * argument; a positive value if this object represents true
    * and the argument represents false; and a negative value if
    * this object represents false and the argument represents true
    * @throws NullPointerException if the argument is {@code null}
    * @see Comparable
    * @since 1.5
    */
    public int compareTo(Boolean b) {
    return compare(this.value, b.value);
    } /**
    * Compares two {@code boolean} values.
    * The value returned is identical to what would be returned by:
    * <pre>
    * Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
    * </pre>
    *
    * @param x the first {@code boolean} to compare
    * @param y the second {@code boolean} to compare
    * @return the value {@code 0} if {@code x == y};
    * a value less than {@code 0} if {@code !x && y}; and
    * a value greater than {@code 0} if {@code x && !y}
    * @since 1.7
    */
    public static int compare(boolean x, boolean y) {
    return (x == y) ? 0 : (x ? 1 : -1);
    } /**
    * Returns the result of applying the logical AND operator to the
    * specified {@code boolean} operands.
    *
    * @param a the first operand
    * @param b the second operand
    * @return the logical AND of {@code a} and {@code b}
    * @see java.util.function.BinaryOperator
    * @since 1.8
    */
    public static boolean logicalAnd(boolean a, boolean b) {
    return a && b;
    } /**
    * Returns the result of applying the logical OR operator to the
    * specified {@code boolean} operands.
    *
    * @param a the first operand
    * @param b the second operand
    * @return the logical OR of {@code a} and {@code b}
    * @see java.util.function.BinaryOperator
    * @since 1.8
    */
    public static boolean logicalOr(boolean a, boolean b) {
    return a || b;
    } /**
    * Returns the result of applying the logical XOR operator to the
    * specified {@code boolean} operands.
    *
    * @param a the first operand
    * @param b the second operand
    * @return the logical XOR of {@code a} and {@code b}
    * @see java.util.function.BinaryOperator
    * @since 1.8
    */
    public static boolean logicalXor(boolean a, boolean b) {
    return a ^ b;
    }
    }

java.lang.Boolean 类源码解析的更多相关文章

  1. java.lang.Void类源码解析_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 在一次源码查看ThreadGroup的时候,看到一段代码,为以下: /* * @throws NullPointerEx ...

  2. Java集合---Array类源码解析

    Java集合---Array类源码解析              ---转自:牛奶.不加糖 一.Arrays.sort()数组排序 Java Arrays中提供了对所有类型的排序.其中主要分为Prim ...

  3. java.lang.String 类源码解读

    String类定义实现了java.io.Serializable, Comparable<String>, CharSequence 三个接口:并且为final修饰. public fin ...

  4. Java集合---Arrays类源码解析

    一.Arrays.sort()数组排序 Java Arrays中提供了对所有类型的排序.其中主要分为Primitive(8种基本类型)和Object两大类. 基本类型:采用调优的快速排序: 对象类型: ...

  5. java.lang.system 类源码解读

    通过每块代码进行源码解读,并发现源码使用的技术栈,扩展视野. registerNatives 方法解读 /* register the natives via the static initializ ...

  6. java.lang.Long 类源码解读

    总体阅读了Long的源码,基本跟Integer类类似,所以特别全部贴出源码,直接注释进行理解. // final修饰符 public final class Long extends Number i ...

  7. java.lang.Byte 类源码浅析

    Byte 类字节,属于Number. public final class Byte extends Number implements Comparable<Byte> { /** * ...

  8. Java集合类:AbstractCollection源码解析

    一.Collection接口 从<Java集合:整体结构>一文中我们知道所有的List和Set都继承自Collection接口,该接口类提供了集合最基本的方法,虽然List接口和Set等都 ...

  9. Java集合:LinkedList源码解析

    Java集合---LinkedList源码解析   一.源码解析1. LinkedList类定义2.LinkedList数据结构原理3.私有属性4.构造方法5.元素添加add()及原理6.删除数据re ...

随机推荐

  1. 2018上C语言程序设计(高级)- 第1次作业成绩

    作业地址 https://edu.cnblogs.com/campus/hljkj/CS2017-01/homework/1638 评分准则 第一次作业各项成绩包括三项: 完成PTA所有题目:20分 ...

  2. apply,call以及bind的区别

    每个函数都包含两个非继承而来的方法:apply()和 call(). 这两个方法的用途都是在特定的作用域中调用函数,实际上等于设置函数体内 this 对象的值. 一.apply() apply()方法 ...

  3. 使用日期操作类(Calendar)获得几秒、几分钟、几小时之前的时间

    public String dealDate(String case_time){ // 日期操作类 Calendar calendar = Calendar.getInstance(); // 当前 ...

  4. Kali Linux Web后门工具、Windows操作系统痕迹清除方法

    Kali Linux Web后门工具 Kali的web后门工具一共有四款,今天只介绍WebaCoo 首先介绍第一个WeBaCoo(Web Backdoor Cookie) WeBaCoo是一款隐蔽的脚 ...

  5. 初探OpenCL之Mac OS上的hello world示例

    了解了深度学习的崛起,引起了目前OpenCL的需求,大致了解一下. 相关内容:http://blog.csdn.net/leonwei/article/details/8880012 本身OpenCL ...

  6. cf374C Inna and Dima dfs判环+求最长链

    题目大意是有一个DIMA四种字母组成的矩阵,要在矩阵中找最长的DIMADIMADIMA……串,连接方式为四方向连接,问最长能找到多少DIMA.字母可以重复访问,如果DIMA串成环,即可以取出无限长的D ...

  7. tensorflow 代码阅读

    具体实现: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/core/framework 『深度长文』Tensorflo ...

  8. 芯灵思Sinlinx A64 Linux&qt编译安装

    开发平台 芯灵思Sinlinx A64 内存: 1GB 存储: 4GB 详细参数 https://m.tb.cn/h.3wMaSKm 开发板交流群 641395230 前提条件搭建好CentOS环境 ...

  9. VBA随机地牢生成

    无聊啊--于是,我想做一个随机地图. 但是我很懒,不想做. 但是身体很诚实. 这次是直接在Excel中制作的地图,但是,VB的执行效率很慢,我代码的效率也很慢,导致,一旦地图长宽稍大,就会出现好几分钟 ...

  10. windows远程登录报错 CredSSP不支持Oracle

    https://support.microsoft.com/en-us/help/4093492/credssp-updates-for-cve-2018-0886-march-13-2018