javaÖеÄclon()ºÍcloneable½Ó¿ÚdzÎö
The clone( ) method generates a duplicate copy of the object on which it is called. Only classes that implement the Cloneable interface can be cloned.
...clone()²úÉúÁËÒ»¸öµ÷ÓÃËüµÄ¶ÔÏóµÄ¸´ÖÆ;Ö»ÓÐʵÏÖÁËCloneable½Ó¿ÚµÄÀà²Å¿ÉÒÔ±»¸´ÖÆ¡£
The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object (that is, a clone ) to be made. If you try to call clone( ) on a class that does not implement Cloneable , a CloneNotSupportedException is thrown. When a clone is made, the constructor for the object being cloned is not called. A clone is simply an exact copy of the original.
Cloneable ½Ó¿ÚûÓж¨ÒåÈκγÉÔ±¡£ËüÓÃÀ´Ö¸Ã÷Ò»¸öÀà¿ÉÒÔÖðλ¸´ÖÆÒ»¸ö¶ÔÏó¡£Èç¹ûÄãÊÔͼ¶ÔÒ»¸öûÓÐʵÏÖcloneable½Ó¿ÚµÄÀàµ÷ÓÃclone()·½·¨£¬Ò»¸öCloneNotSupportedException ¾Í»áÅ׳ö¡£ÔÚ¸´ÖÆÊ±£¬±»¸´ÖƵĶÔÏóµÄ¹¹ÔìÆ÷²¢Ã»Óб»µ÷Ó᣸´ÖƶÔÏó¾ÍÊÇÔÀ´¶ÔÏóµÄ¿½±´¡£
Cloning is a potentially dangerous action, because it can cause unintended side effects. For example, if the object being cloned contains a reference variable called obRef, then when the clone is made, obRef in the clone will refer to the same object as does obRef in the original. If the clone makes a change to the contents of the object referred to by obRef, then it will be changed for the original object, too. Here is another example. If an object opens an I/O stream and is then cloned, two objects will be capable of operating on the same stream. Further, if one of these objects closes the stream, the other object might still attempt to write to it, causing an error.
¸´ÖÆÊÇÒ»ÖÖ´æÔÚDZÔÚΣÏÕµÄÐÐΪ£¬ÒòΪËü»áÒýÆðһЩÒâÏë²»µ½µÄ¸º×÷Óá£ÀýÈ磬Èç¹û±»¸´ÖƵĶÔÏó°üº¬Ò»¸öÃûΪ obRef ÒýÓñäÁ¿£¬ÔÚ¸´ÖÆÊ±£¬¸´ÖƶÔÏóµÄ obReºÍf ÔÀ´¶ÔÏóµÄ obRef ¶¼»áÖ¸Ïòͬһ¸ö¶ÔÏó¡£Èç¹û¸´ÖƶÔÏó¶Ô obRef Ö¸ÏòµÄ¶ÔÏóµÄÄÚÈÝ×ö³öһЩ¸Ä±ä£¬¶ÔÓÚÔÀ´¶ÔÏóÀ´Ëµ£¬Ò²¾ÍÏ൱ÓÚËüÒ²±»¸Ä±äÁË¡£»¹ÓÐÁíÒ»¸öÀý×Ó£¬Èç¹ûÒ»¸ö²Ù×÷I/OÁ÷µÄ¶ÔÏ󱻸´ÖÆÁË£¬ÕâÁ½¸ö¶ÔÏó¶¼ÄܶÔͬһI/OÁ÷½øÐвÙ×÷¡£½øÒ»²½Ëµ£¬Èç¹ûËüÃÇÁ½¸öÖеÄÒ»¸ö¹Ø±ÕÁ
Ïà¹ØÎĵµ£º
´úÂëÈçÏ£º
¡¡¡¡ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
¡¡¡¡package com.example.pinyin.demo2;
¡¡¡¡import net.sourceforge.pinyin4j.PinyinHelper;
¡¡¡¡import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
¡¡¡¡import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
¡¡¡¡import net.sourceforge.pinyin4j.form ......
×î¼Ñ´ð°¸
1. ±àд·¶ÀýÎĵµ
public class TestNative
{
private native static int Max(int a,int b);
public static void main(String[] args)
{
System.out.println(Max(4,5));
}
static
{
System.loadLibrary("VCdll");
}
}
ÆäÖÐ
LoadLibraryÖеÄDLLÎļþÃû³Æ¿ÉÒÔ ......
×î½üÒªÖØÐÂѧϰJava£¬ÕÒ¸öÀý×ÓÀ´Êµ¼ù£¬ÔÚÍøÉÏÕÒÁ˺ܶàÀý³ÌÀ´¿´£¬×Ô¼ºÖØÐ±àдÁËÒ»¸ö̰ʳÉßµÄÀý×Ó£¬¼ÇÔÚÕâÀï¡£
1.SnakeModel.java
import java.util.Observable;
import java.util.LinkedList;
import java.util.Arrays;
import java.util.Random;
import javax.swing.*;
//ObservableÀàÒ»°ã´ú±íÊý¾Ý£¬ÊµÏÖ½Ó¿ÚRunna ......
ÉÏ´Î談過ÁËʹÓÃiText產ÉúPDF檔£¬這´Î換³É來談談ʹÓÃJExcel來產ÉúEXCEL檔µÄ·½·¨¡£
Ê×ÏÈ£¬Ïȵ½ËûµÄSourceForgeÖ÷頁ÃædownloadÏà關µÄAPI檔°¸¡£
http://sourceforge.net/projects/jexcelapi/
»ò
http://www.andykhan ......