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
Ïà¹ØÎĵµ£º
1. Ó¦Ó÷¶Î§
±¾¹æ·¶Ó¦ÓÃÓÚ²ÉÓÃJ2EE¹æ·¶µÄÏîÄ¿ÖУ¬ËùÓÐÏîÄ¿ÖеÄJAVA´úÂ루º¬JSP£¬SERVLET£¬JAVABEAN£¬EJB£©¾ùÓ¦×ñÊØÕâ¸ö¹æ·¶¡£Í¬Ê±£¬Ò²¿É×÷ΪÆäËüÏîÄ¿µÄ²Î¿¼¡£
2. Éè¼ÆÀàºÍ·½·¨
2.1 ´´½¨¾ßÓкÜÇ¿ÄÚ¾ÛÁ¦µÄÀà
·½·¨µÄÖØÒªÐÔÍùÍù±ÈÀàµÄÖØÒªÐÔ¸üÈÝÒ×Àí½â£¬·½·¨ÊÇÖ¸Ö´ÐÐÒ»¸öͳһº¯ÊýµÄÒ»¶Î´úÂë¡£Àà³£± ......
1.String str = new String("abc"); ÇëÎʶ¨ÒåÁ˼¸¸ö¶ÔÏó¡£¶¨ÒåÁËÁ½¸ö¶ÔÏó£¬Ò»¸ö"abc", Ò»¸öÊÇnew String().<String s = "abc";Ê×Ïȵ½¶ÑÖвéÕÒֵΪ"abc"µÄ¶ÔÏó£¬Ã»ÓоÍн¨Ò»¸ö¶ÔÏó£¬"abc"±¾Éí¾ÍÊÇÒ»¸ö¶ÔÏó¡£>
2.ÃæÏò¶ÔÏóµÄ¶«Î÷£ºabstract & interfaceµÄ¸÷×ÔµÄ×÷Óã¬Çø±ð¡£
3.ÃæÏò¶ÔÏóµÄÌØÕ÷£¬ÒÔ¼°ÔõôʵÏֵġ£1 ......
×î½üÐèÒªÖÆ×÷java desktop applicationµÄ°²×°³ÌÐò¡£
ºÃ²»ÈÝÒ×ÔÚÍøÉÏdownÁ˸öinstallanywhere9°²×°²¢ÆÆ½â£¬ ÓÃÆðÀ´»¹Í¦Ë³Àû£¬¹¦ÄܱȽÏÇ¿´ó£¬Ðí¶àµØ·½¿ÉÒÔ¶¨ÖÆ£¬µ±È»×ö³öÀ´µÄ³ÌÐòÔÚ°²×°Ê±Ò²Ëæ´¦¿É¼ûinstallanywhereµÄÉíÓ°£¬ÉÌÒµÈí¼þÂû°ì·¨¡£
ºóÀ´³ÌÐòÔÚÔËÐйý³ÌÖУ¬·¢ÏÖ×ÔÒÔΪÉèÖýøÈ¥ÁËjava desktop applicationµÄjreµ ......
javaµÄ·¶ÐÍ»úÖÆ¿´ÆðÀ´ÓеãÏñC++µÄÄ£°æ£¬µ«Ïà±È½ÏC++µÄÄ£°æÀ࣬javaÖеķ¶ÐÍûÓйؼü×Ötemplate£¬²¢ÇÒÓÐ×Ų»Í¬µÄʵÏÖ»úÖÆ£¨±¾ÖÊÇø±ð£©¡£
·¶ÐÍÀà
ÏÈ¿´Ò»¸ö·¶ÐÍÀàµÄÀý×Ó£º
public class Demo1<T> {
private T value;
public Demo1(T value) {
&n ......