• Java-学习日记(Shell与String底层原理)


    Java杂记-2020.08.07

    @Test中测试所有getter,setter方法

    最近一周在写codereview,相关技术是kmock1.0.19,gradle

    • build.gradle中配置文件
        testCompile 'pl.pojo:pojo-tester:0.7.6'
        testCompile('junit:junit:4.12')
        testCompile('kmock:kmock:1.0.19')
    
    • @Test中的使用,这样就能覆盖所有getter,setter方法了
        @Test
        public void ExcelInvoiceRes(){
            // given
            final Class<?> classUnderTest = ExcelInvoiceRes.class;
            // when
            // then
            assertPojoMethodsFor(classUnderTest).quickly().testing(Method.GETTER, Method.SETTER)
                    .testing(Method.CONSTRUCTOR)
                    .areWellImplemented();
        }
    

    Shell面试题:批量生成随机字符文件名

    for i in {1..10}
     do
       filename=$(uuidgen|tr '0-9' 'a-z'|cut -c 1-10)
       touch ${filename}_empirefree.html
     done
    
    

    删除以 .html结尾的文件

    find . -name '*.html'| xargs rm -rf
    

    Shell面试题:批量修改文件名

    for i in $(ls *html)
    do
      rn=$(echo $i|cut -c -10)
      mv $i $(rn).HTML
    done
    
    

    Shell面试题:https://blog.51cto.com/13520779/2093146

    String和final String

    都知道String内部是设置成final的,因为执行效率高和安全性这两个优点,前面加final的话就类似常量了,具体如下

    String a = "a";
    System.out.println((a + "b") == "ab");      //false
    System.out.println(("a" + "b") == "ab");    //true
    final String b = "b";
    System.out.println(("a" + b) == "ab");      //true
    System.out.println((a + b) == "ab");        //false
    

    执行效率高:当子类重写(override)父类某个方法,JVM如果是用final修饰的方法,就能直接用,效率高,而不用去虚函数表里面寻找
    安全性:多线程中,如果String被修改了,会导致安全问题(String a = "b"只是修改了变量指引,实际"a"的内存并没有消失)。还有就是Hashmap中如果String可变,就会产生不同的 Hash值,这也会引发安全性

  • 相关阅读:
    关于 语文物理 和 数学物理
    黎耀天 共量子 我拍了 几张照片 给你们 当 素材
    看了 陈记抄 同学 的 《随便聊聊之量子力学中的散射理论》
    极坐标系 下的 牛顿第二定律
    jQuery 工具类库集锦
    Javascript跨域问题解决方案
    js禁止从浏览器缓存读取消息
    关于双击事件.MouseEvent.DOUBLE_CLICK
    div的打开与关闭js
    利用通道完成文件的复制 (非直接缓存区)
  • 原文地址:https://www.cnblogs.com/meditation5201314/p/13454727.html
Copyright © 2020-2023  润新知