µÚ1Ìõ How to Write an Equality Method in Java
http://www.artima.com/lejava/articles/equality.html
How to Write an Equality Method in Java
by Martin Odersky, Lex Spoon, and Bill Venners
June 1, 2009
Summary
This article describes a technique for overriding the equals method that preserves the contract of equals even when subclassses of concrete classes add new fields.
In Item 8 of Effective Java1, Josh Bloch describes the difficulty of preserving the equals contract when subclassing as a “fundamental problem of equivalence relations in object-oriented languages.” Bloch writes:
There is no way to extend an instantiable class and add a value component while preserving the equals contract, unless you are willing to forgo the benefits of object-oriented abstraction.
Chapter 28 of Programming in Scala shows an approach that allows subclasses to extend an instantiable class, add a value component, and nevertheless preserve the equals contract. Althou ......
µÚ1Ìõ How to Write an Equality Method in Java
http://www.artima.com/lejava/articles/equality.html
How to Write an Equality Method in Java
by Martin Odersky, Lex Spoon, and Bill Venners
June 1, 2009
Summary
This article describes a technique for overriding the equals method that preserves the contract of equals even when subclassses of concrete classes add new fields.
In Item 8 of Effective Java1, Josh Bloch describes the difficulty of preserving the equals contract when subclassing as a “fundamental problem of equivalence relations in object-oriented languages.” Bloch writes:
There is no way to extend an instantiable class and add a value component while preserving the equals contract, unless you are willing to forgo the benefits of object-oriented abstraction.
Chapter 28 of Programming in Scala shows an approach that allows subclasses to extend an instantiable class, add a value component, and nevertheless preserve the equals contract. Althou ......
Õ⼸Ìì²Î¿¼ÓйØ×ÊÁÏ£¬½èÖúinstall4jÈí¼þ×ÜËã³õ²½Ñ§»áÁËJava³ÌÐò£¨jar£©´ò°ü³É¿É°²×°µÄWindowsÓ¦ÓóÌÐòµÄ·½·¨¡£
Ïà¹ØÈí¼þÔÚ£ºhttp://download.csdn.net/¿ÉÒÔËÑË÷µ½
ÒÔÏÂÊǹý³Ì¼Ç¼£º
1.
ͨ¹ý¸÷ÖÖ·½Ê½Éú³ÉÒ»¸ö¿ÉÖ´ÐеÄjarÎļþ£¨Çë²Î¿¼£ºhttp://blog.sina.com.cn/s/blog_65bb33240100ii4r.html£©
2.
Éú³ÉÒ»¸ö×Ô¼ºµÄjreÀ¦°óÎļþºó׺ÃûΪtar.gz
3.
ͨ¹ýinstall4j½øÐÐJava³ÌÐòµÄ´ò°ü´¦Àí
½ÓÏÂÀ´Öصã¼Ç¼µÚ¶þ²½ºÍµÚÈý²½
¸½Í¼¹©²Î¿¼
http://download.csdn.net/source/2304884
http://download.csdn.net/source/2303298
µÚ¶þ²½£º
ÔËÐÐinstall4j£¬Ñ¡ÔñÏîÄ¿²Ëµ¥£¨Project£©ÏµÄÉú³ÉÒ»¸öJRE°ó¶¨Îļþ£¨Create a JRE Bundle£©£¬È»ºóµ¯³öÉú³ÉÏòµ¼¶Ô»°¿òµã»÷Next½øÈëÑ¡ÔñJREµÄ¶Ô»°¿ò£¬Ñ¡Ôñä¯ÀÀ°´Å¥£¨µÚÒ»ÅÅ×îÓұߣ©µ¯³ö
Ñ¡ÔñÎļþ¼Ð¶Ô»°¿ò£¬Ñ¡ÔñÄúÒªÉú³ÉÀ¦°óÎļþ£¨¼´tar.gzÎļþ£©µÄĿ¼£¬µã»÷Open°´Å¥
ÊäÈëÄúµÄjre°æ±¾Èç1.5
ÊäÈëÀ¦°óÎļþÃû£¬Ëæ±ãÊäÈëÒ»¸ö£¬×îºÃÊÇÓ¢ÎÄ×Ö·ûµÄ£¨ÖÐÎĵϰ»ØÏÔΪ¡õ²»ºÃÇø·Ö£¬àË¡£Ã»°ì·¨Ã»ÕÒµ½Ö§³ÖÖÐÎĵģ©
µã»÷next¿´µ½Ã»ÓУ¬ÕýÔÚ°ïÄúÉú³ÉÀ¦°óÎļþÄØ£¬Èç¹ûÄúµÄJRE²»ÊǾ«¼ ......
Ò»¡¢ÏòÉÏתÐÍ¡£
ͨË׵ؽ²¼´Êǽ«×ÓÀà¶ÔÏóתΪ¸¸Àà¶ÔÏó¡£´Ë´¦¸¸Àà¶ÔÏó¿ÉÒÔÊǽӿڡ£
1£¬ÏòÉÏתÐÍÖеķ½·¨µ÷Óá£
¿´ÏÂÃæ´úÂ룺
package com.wensefu.others;
public class Animal {
public void eat(){
System.out.println("animal eatting...");
}
}
class Bird extends Animal{
public void eat(){
System.out.println("bird eatting...");
}
public void fly(){
System.out.println("bird flying...");
}
}
class Main{
public static void main(String[] args) {
Animal b=new Bird(); //ÏòÉÏתÐÍ
b.eat();
//! error: b.fly(); bËäÖ¸Ïò×ÓÀà¶ÔÏ󣬵«´Ëʱ¶ªÊ§fly()·½·¨
dosleep(new Male());
dosleep(new Female());
}
public static void dosleep(Human h) {
h.sleep();
}
}
package com.wensefu.others;
public class Human {
public void sleep() {
System.out.println("Human sleep..");
}
}
class Male extends Human {
@Override
public void sleep() {
System.out.println("Male sleep..");
}
}
class Fem ......
±äÁ¿£º´æ´¢Êý¾ÝµÄ»ù±¾µ¥Ôª£»Ò»¸öÊý¾Ý´æ´¢¿Õ¼äµÄ±íʾ.
»ù±¾Êý¾ÝÀàÐÍ(8ÖÖ)£º
byte(1)-->short(2)-->int(4)-->long(8) float(4)-->double(8) boolean(1) char(2)
ÒýÓÃÊý¾ÝÀàÐÍ£º
String¡¢Êý×é¡¢Àà¡¢½Ó¿Ú¡¢¶ÔÏó ......
ϵͳ×Ô¶¯Å׳öµÄÒì³£
ËùÓÐϵͳ¶¨ÒåµÄ±àÒëºÍÔËÐÐÒì³£¶¼¿ÉÒÔÓÉϵͳ×Ô¶¯Å׳ö£¬³ÆÎª±ê×¼Òì³££¬²¢ÇÒ Java Ç¿ÁÒµØÒªÇóÓ¦ÓóÌÐò½øÐÐÍêÕûµÄÒì³£´¦Àí£¬¸øÓû§ÓѺõÄÌáʾ£¬»òÕßÐÞÕýºóʹ³ÌÐò¼ÌÐøÖ´ÐС£
Óï¾äÅ׳öµÄÒì³£
Óû§³ÌÐò×Ô¶¨ÒåµÄÒì³£ºÍÓ¦ÓóÌÐòÌØ¶¨µÄÒì³£,±ØÐë½èÖúÓÚ throws ºÍ throw Óï¾äÀ´¶¨ÒåÅ׳öÒì³£¡£
throwÊÇÓï¾äÅ׳öÒ»¸öÒì³£¡£
Óï·¨£ºthrow (Òì³£¶ÔÏó);
throw e;
throwsÊÇ·½·¨¿ÉÄÜÅ׳öÒì³£µÄÉùÃ÷¡£(ÓÃÔÚÉùÃ÷·½·¨Ê±£¬±íʾ¸Ã·½·¨¿ÉÄÜÒªÅ׳öÒì³£)
Óï·¨£º[(ÐÞÊηû)](·µ»ØÖµÀàÐÍ)(·½·¨Ãû)([²ÎÊýÁбí])[throws(Òì³£Àà)]{......}
public void doA(int a) throws Exception1,Exception3{......}
¾ÙÀý£º
throws E1,E2,E3Ö»ÊǸæËß³ÌÐòÕâ¸ö·½·¨¿ÉÄÜ»áÅ׳öÕâЩÒì³££¬·½·¨µÄµ÷ÓÃÕß¿ÉÄÜÒª´¦ÀíÕâЩÒì³££¬¶øÕâЩÒì³£E1£¬E2£¬E3¿ÉÄÜÊǸú¯ÊýÌå²úÉúµÄ¡£
throwÔòÊÇÃ÷È·ÁËÕâ¸öµØ·½ÒªÅ׳öÕâ¸öÒì³£¡£
È磺 void doA(int a) throws Exception1,Exception3{
try{
&nb ......
1.
BufferedReader in = new BufferedReader(new FileReader("Ô¶³ÌÎļþ"));
in.readLine() ;
l ʹÓà Java ²Ù×÷Îı¾ÎļþµÄ·½·¨Ïê½â
http://java.ccidnet.com/art/3737/20041108/523627_1.html
l FileReader ÊÇʲôÀࣿºÍ FileInputStream ÓÐʲô²»Í¬£¿£¿£¿
http://book.hackbase.com/ask2/ask107572.htm
1. FileÀà
1 £© File Àà½éÉÜ£¨¡¶ core java ¡· 638 Ò³£©
File Àà·â×°Á˶ÔÓû§»úÆ÷µÄÎļþϵͳ½øÐвÙ×÷µÄ¹¦ÄÜ¡£ÀýÈ磬¿ÉÒÔÓà File Àà»ñµÃÎļþÉÏ´ÎÐ޸ĵÄʱ¼äÒÆ¶¯£¬
»òÕß¶ÔÎļþ½øÐÐɾ³ý¡¢ÖØÃüÃû¡£»»¾ä»°Ëµ£¬Á÷Àà¹Ø×¢µÄÊÇÎļþÄÚÈÝ£¬¶ø File Àà¹Ø×¢µÄÊÇÎļþÔÚ´ÅÅÌÉϵĴ洢
¡£
File ÀàµÄÖ÷Òª·½·¨ÓУº getName(),getCanonicalFile(),lastModified(),isDerector(),isFile(),getPath()
µÈ£»
2 £© File ÀàÓë FileInputStream ÀàµÄÇø±ð£º
Á÷Àà¹Ø×¢µÄÊÇÎļþÄÚÈÝ£¬¶ø File Àà¹Ø×¢µÄÊÇÎļþÔÚ´ÅÅÌÉϵĴ洢¡£
File ²»ÊôÓÚÎļþÁ÷ , Ö»ÄÜ´ú±íÒ»¸öÎļþ»òÊÇĿ¼µÄ·¾¶Ãû¶øÒÑ¡£
Ìáʾ£º£¨¡¶ core java ¡· 639 Ò³£©
Èç¹û´¦ÀíÎļþ»òÕßĿ¼Ãû£¬¾ÍÓ¦¸ÃʹÓà File ¶ÔÏ󣬶ø²»ÊÇ×Ö·û´®¡£ÀýÈ磬 Fil ......