Effective Java: Item 1
Static Factory Methods
Four Advantages:
1) have names
2) not required to create a new object each time they are invoked
3) return an object of any subtype of their return type
4) reduce the verbosity of creating parameterized type instances.(for example: newInstance() method)
Ïà¹ØÎĵµ£º
javaÖÐÒì³£µÄÁ½ÖÖ´¦Àí£º
1.try...catch....finally ´æÔÚÓ뵱ǰµÄÒì³£´¦ÀíÀ࣬±íʾµ±Ç°ÓÉ×Ô¼ºµÄ·½·¨À´´¦Àí
2.Throw ½«µ±Ç°Òì³£Å׳ö £¬½»ÓÉÉϼ¶À´´¦Àí¡£
try...catch....finallyµÄ´¦ÀíÁ÷³Ì£º
½«³öÏÖÒì³£µÄÓï¾ä·ÅÔÚtryÖУ¬Ò»¶Î´ËÓï¾ä³ö´í£¬³ÌÐò»áÔÝÍ£Ö´ÐУ¬Òì³£´¦Àí»úÖƾÍÈ¥½Ó¹Ü³ÌÐò£¬
½ ......
ÉÐѧÌÃѧϰjava¸ÐÊÜ
¡¾Ñ§Ô±¹ÊÊ¡¿À´×ÔÉÐѧÌÃÕæÈËÕæÊ£¨www.bjsxt.com£©
±¾ÎÄ×÷Õߣ¬³É£¬ÊÇÒ»¸öÓÄĬµÄѧԱ£¬¼òµ¥¸ÅÒªÒ»ÏÂËûµÄÇé¿ö£¬ËûÊÇÊýѧϵµÄ£¬×ÔÉÐѧÌñÏÒµºóÔø¾ÍÒµÓÚÎÄ˼£¨ÑÇÂíÑ·£©ÏîÄ¿£¬ÏÖ¾ÍÖ°ÓÚÑÇÐŹ«Ë¾£¬Ã¿Ò»´ÎÌøÔ¾¶¼±ÈÒÔÇ°¸ü¸ß£¡
´Ó´óѧ±ÏÒµµ½ÔÙѧϰÔÙµ½¹¤×÷£¬¸ÕºÃ ......
ËãÊõÒì³£ÀࣺArithmeticExecption
¿ÕÖ¸ÕëÒì³£ÀࣺNullPointerException
ÀàÐÍÇ¿ÖÆת»»Òì³££ºClassCastException
Êý×鸺ϱêÒì³££ºNegativeArrayException
Êý×éϱêÔ½½çÒì³££ºArrayIndexOutOfBoundsException
Î¥±³°²È«ÔÔòÒì³££ºSecturityException
ÎļþÒѽáÊøÒì³££ºEOFException
ÎļþδÕÒµ½Òì³££ºFileNotFound ......
class Link
{
private Node head;
public Link(Node head)
{
this.head=head;
}
public void addNode(Node node)
{
Node p=head;
while(true)
{
if(!p.hasNext())
{
p.setNext(node);
break;
}
p=p.getNext();
}
}
//²åÈë½Ú
public void insertNode(Node p,Node q)
{
q.setNext(p.getNext());
p.se ......