JAVA の文字列配列のディープ コピーを実装するコードを示す必要があります。以下は私が開発したコードです。それが正しいかどうかは誰でも確認できますか?
public class Paper implements Cloneable{
private String Type ;
private String[] Text ;
//Default constructor to initialize variables.
public Paper()
{
this.Type="" ;
this.Text = new String[0] ;
}
//Necessary constructor.
public Paper(String Type, String[] Text)
{
this.Type= Type;
//Deep copy
this.Text = new String[Text.length] ;
this.Text = Text.clone() ;
//Flat Copy
this.Text = Text ;
}
//Here we implements the interface "Cloneable" to make deep copy when we want to
//extend an array of Paper objects.
public Object clone()
{
try
{
Paper cloned = (Paper) super.clone();
cloned.Text = (String[])Text.clone();
return cloned;
}
catch(CloneNotSupportedException e)
{
return null;
}
}