JAVA Tips Oct.2017

1.抽象类和接口:http://www.cnblogs.com/dolphin0520/p/3811437.html
2.异常处理
public void dothing(int a,int b) throws Exception1,Exception3 {
           try{
                 //......

           }catch(Exception1 e){
              throw e;
           }catch(Exception2 e){
              System.out.println("自己打印提示,不抛出");
           }
           if(a!=b)
              throw new  Exception3("自定义异常");
}
复制代码
代码块中可能会产生3个异常,(Exception1,Exception2,Exception3)。
如果产生Exception1异常,则捕获之后再抛出,由该方法的调用者去处理。
如果产生Exception2异常,则该方法自己处理了(即打印出字符串:自己打印提示,不抛出)。所以该方法就不会再向外抛出Exception2异常了,void dothing() throws Exception1,Exception3 里面的Exception2也就不用写了(当然你写了也不会报错的),throws 就是声明可能抛出的错误,而Exception2 并未做出抛出操作。
而Exception3异常是该方法的某段逻辑出错,程序员自己做了处理,在该段逻辑错误的情况下抛出异常Exception3,则该方法的调用者也要处理此异常。
3.JAVA泛型:http://blog.csdn.net/s10461/article/details/53941091
4.JAVA反射
5.java的String比较:https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java 要用.equals,因为==只能对string pool里面的奏效,如果一个在heap一个在string pool,用==会出错。

评论

此博客中的热门博文

225 Implement Stack using Queues

232. Implement Queue using Stacks

20. Valid Parentheses