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值,这也会引发安全性