1. try catch finally 中的return
public class testfinally {
@Test
public void test1(){
System.out.println(theone());//3
System.out.println(thetwo());//0
System.out.println(thethree());//3 0
}
public static int theone(){
int i = 0;
try {
return i;
} catch (Exception e){
return i+1;
} finally {
return 3;
}
}
public static int thetwo(){
int i = 0;
try {
return i;
} catch (Exception e){
return i+1;
} finally {
i = 3;
}
}
public static int thethree(){
int i = 0;
try {
return i;
} catch (Exception e){
return i+1;
} finally {
System.out.println(3);
}
}
}
知识点:
try中return后不会直接结束,而是会先把这个返回值挂起,然后去执行finally语句,如果finally语句中有return,还会把这个挂起值覆盖,最后返回给调用者的是这个挂起值.
2. String类型普通创建和常量池创建
public class TestString {
@Test
public void test1(){
String a = "aaa";
String b = "bbb";
String c = "aaabbb";
String d = "aaa"+"bbb";
String e = a+b;
System.out.println(c==d);//true
System.out.println(c==e);//false
String f = e.intern();
System.out.println(c==f);//true
}
}