javaÖеĹؼü×Ö£¨transient£©
transientÕâ¸ö¹Ø¼ü×Ö²¢²»³£¼û£¬Ö÷ÒªÓ¦ÓÃÔÚjavaµÄÐòÁл¯·½Ãæ¡£ÕâÀïÎÒÔÙ¶à˵£¬×ªÒ»ÆªÀÏÍâµÄÎÄÕ£¬ºÜÉú¶¯£¬ÐÀÉͰÉ
Be Careful With Transient Data
Java's serialization provides an elegant, and easy to use mechanism for making an object's state persistent. While controlling object serialization, we might have a particular object data member that we do not want the serialization mechanism to save.
To turn off serialization on a certain field of an object, we tag that field of the class of our object with the Java's "transient" keyword. This, to low-level parts of the Java virtual machine, is an indication that the transient variable is not part of the persistent state of an object.
First, let's have some backgrounder code with Java's serialization.
Suppose we define a class as:
public class LoggingInfo implements java.io.Serializable
{
private Date loggingDate = new Date();
private String uid;
private transient String pwd;
LoggingInfo(String user, String password)
{
uid = user;
pwd = password;
}
public String toString()
{
String password=null;
if(pwd == null)
{
password = "NOT SET";
}
else
{
password = pwd;
}
return "logon info: \n " + "user: " + uid +
"\n
Ïà¹ØÎĵµ£º
δÍê³É ´ýÍêÉÆ
public class MagicCube {
/**
* Áù¸öÃæµÄϱêÖµ
* ¡õ5
* ¡õ¡õ¡õ¡õ 1234 ÕâËĸöÁ¬ÌåÕý·½ÐÎÏòºó˳ʱÕë°üΧ ÐγÉͲ״ È»ºó °Ñ5ºÍ6¿ÛÉÏ ¾ÍÐγÉÕý·½Ìå
* ¡õ6
*/
public static void main(String[] args) {
MagicCube mb = new MagicCube();
int i = 0;
for (Face f : mb.faces ......
2009Äê10ÔÂ25ÈÕ£¬µÃÒ»Êéµê200ÔªÂòÁËËı¾Êéj2se»ù´¡½Ì³Ì£¬j2eeÓ¦Óÿª·¢Ïê½â£¬javaÏîÄ¿¿ª·¢È«³Ìʵ¼£¬java web¿ª·¢ËÙѧ±¦µäÊ鿪ʼ
2010Äê2ÔÂ3ÈÕ£¬µÚÒ»Ì×»ùÓÚú¿ó°²È«¹ÜÀíµÄÈí¼þÄ£Ðͼ°Æä²¿·Ö´úÂë³ÉÐÍ
Èý¸öÔ£¬ÕâÊÇÒ»³¡Ø¬ÃΣ¬²»¹ýÕâÈý¸öÔ£¬ÓÖÊÇÒ»ÖÖ¾ªÏ²ºÍ¿ìÀÖ
´ÓÊý¾ÝÀàÐÍ£¬Óï·¨½á¹¹£¬jdk ¹ýÑ»·£¬´³Êý×飬¼¯ºÏ£¬µü´ú£¬¶ÓÁУ ......
1.½Ó¿ÚµÄ¶¨Ò壺
interface ½Ó¿ÚÃû
{ ½Ó¿ÚÌ壻 }
×¢Ò⣺½Ó¿ÚÌåÖÐÖ»Äܰüº¬³£Á¿¶¨ÒåºÍ·½·¨¶¨ÒåÁ ......
1.String str = new String("abc"); ÇëÎʶ¨ÒåÁ˼¸¸ö¶ÔÏó¡£¶¨ÒåÁËÁ½¸ö¶ÔÏó£¬Ò»¸ö"abc", Ò»¸öÊÇnew String().<String s = "abc";Ê×Ïȵ½¶ÑÖвéÕÒֵΪ"abc"µÄ¶ÔÏó£¬Ã»ÓоÍн¨Ò»¸ö¶ÔÏó£¬"abc"±¾Éí¾ÍÊÇÒ»¸ö¶ÔÏó¡£>
2.ÃæÏò¶ÔÏóµÄ¶«Î÷£ºabstract & interfaceµÄ¸÷×ÔµÄ×÷Óã¬Çø±ð¡£
3.ÃæÏò¶ÔÏóµÄÌØÕ÷£¬ÒÔ¼°ÔõôʵÏֵġ£1 ......