• Java自动装箱测试


    Java自动装箱测试

    测试代码

    import lombok.extern.slf4j.Slf4j;
    
    import java.util.Objects;
    
    @Slf4j
    public class AutoBoxMain {
        public static void main(String[] args) {
    
            {
                int i = 1;
                int i2 = 1;
                long l = 1L;
                float f = 1F;
                double d = 1D;
                log.info("int 1 equals int 1 is {}", Objects.equals(i, i2));
                log.info("int 1 equals long 1 is {}", Objects.equals(i, l));
                log.info("int 1 equals float 1 is {}", Objects.equals(i, f));
                log.info("int 1 equals double 1 is {}", Objects.equals(i, d));
            }
    
            log.info("");
    
            {
                int i = 1;
                int i2 = 1;
                long l = 1L;
                float f = 1F;
                double d = 1D;
                log.info("int 1 == int 1 is {}", i == i2);
                log.info("int 1 == long 1 is {}", i == l);
                log.info("int 1 == float 1 is {}", i == f);
                log.info("int 1 == double 1 is {}", i == d);
            }
    
            log.info("");
    
            {
                int i = 200;
                int i2 = 200;
                long l = 200L;
                float f = 200F;
                double d = 200D;
                log.info("int 200 equals int 200 is {}", Objects.equals(i, i2));
                log.info("int 200 equals long 200 is {}", Objects.equals(i, l));
                log.info("int 200 equals float 200 is {}", Objects.equals(i, f));
                log.info("int 200 equals double 200 is {}", Objects.equals(i, d));
            }
    
            log.info("");
    
            {
                int i = 200;
                int i2 = 200;
                long l = 200L;
                float f = 200F;
                double d = 200D;
                log.info("int 200 == int 200 is {}", i == i2);
                log.info("int 200 == long 200 is {}", i == l);
                log.info("int 200 == float 200 is {}", i == f);
                log.info("int 200 == double 200 is {}", i == d);
            }
    
            log.info("");
    
            {
                Integer i = 1;
                Integer i2 = 1;
                Long l = 1L;
                Float f = 1F;
                Double d = 1D;
                log.info("Integer 1 equals Integer 1 is {}", Objects.equals(i, i2));
                log.info("Integer 1 equals Long 1 is {}", Objects.equals(i, l));
                log.info("Integer 1 equals Float 1 is {}", Objects.equals(i, f));
                log.info("Integer 1 equals Double 1 is {}", Objects.equals(i, d));
                log.info("Integer 1 == Integer 1 is {}", i == i2);
            }
    
            log.info("");
    
            {
                Integer i = 200;
                Integer i2 = 200;
                Long l = 200L;
                Float f = 200F;
                Double d = 200D;
                log.info("Integer 200 equals Integer 200 is {}", Objects.equals(i, i2));
                log.info("Integer 200 equals Long 200 is {}", Objects.equals(i, l));
                log.info("Integer 200 equals Float 200 is {}", Objects.equals(i, f));
                log.info("Integer 200 equals Double 200 is {}", Objects.equals(i, d));
                log.info("Integer 200 == Integer 200 is {}", i == i2);
            }
    
        }
    
    }
    
    

    打印结果

    int 1 equals int 1 is true
    int 1 equals long 1 is false
    int 1 equals float 1 is false
    int 1 equals double 1 is false
    
    int 1 == int 1 is true
    int 1 == long 1 is true
    int 1 == float 1 is true
    int 1 == double 1 is true
    
    int 200 equals int 200 is true
    int 200 equals long 200 is false
    int 200 equals float 200 is false
    int 200 equals double 200 is false
    
    int 200 == int 200 is true
    int 200 == long 200 is true
    int 200 == float 200 is true
    int 200 == double 200 is true
    
    Integer 1 equals Integer 1 is true
    Integer 1 equals Long 1 is false
    Integer 1 equals Float 1 is false
    Integer 1 equals Double 1 is false
    Integer 1 == Integer 1 is true
    
    Integer 200 equals Integer 200 is true
    Integer 200 equals Long 200 is false
    Integer 200 equals Float 200 is false
    Integer 200 equals Double 200 is false
    Integer 200 == Integer 200 is false
    
  • 相关阅读:
    1055 The World's Richest (25 分)
    1048 Find Coins (25 分)散列
    经典多线程问题(三)-子线程与主线程的循环打印
    经典多线程问题(二)-生产者消费者问题
    源码分析 CurrentHashMap 1.8
    源码分析 CurrentHashMap 1.7
    源码分析 HashTable与CurrentHashMap1.7与currentHashMap1.8对比
    源码分析 HashMap 1.8
    源码分析 HashMap 1.7
    Linux复习(常用命令)
  • 原文地址:https://www.cnblogs.com/fengzhentian/p/13612361.html
Copyright © 2020-2023  润新知