當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java CompositeName clone()用法及代碼示例


javax.naming.CompositeName類的clone()方法用於返回此複合名稱對象的副本。如果您對此原始複合名稱的組件進行了任何更改,都不會影響CompositeName對象的新副本,反之亦然。

用法:

public Object clone()

參數:此方法不接受任何內容。



返回值:此方法返回此複合名稱的非空副本。

下麵的程序說明CompositeName.clone()方法:
程序1:

// Java program to demonstrate 
// CompositeName.clone() 
  
import javax.naming.CompositeName; 
import javax.naming.InvalidNameException; 
  
public class GFG { 
    public static void main(String[] args) 
        throws InvalidNameException 
    { 
  
        // create Composite name object 
        CompositeName compositeName 
            = new CompositeName("x/y"); 
  
        // create clone object 
        CompositeName cloneComposite 
            = (CompositeName)compositeName.clone(); 
  
        // print CompositeName 
        System.out.println("Clone CompositeName:"
                           + cloneComposite); 
    } 
}
輸出:
Clone CompositeName:x/y

程序2:

// Java program to demonstrate 
// CompositeName.clone() method 
  
import java.util.Enumeration; 
  
import javax.naming.CompositeName; 
import javax.naming.InvalidNameException; 
  
public class GFG { 
    public static void main(String[] args) 
        throws InvalidNameException 
    { 
  
        // create Composite name object 
        CompositeName compositeName 
            = new CompositeName("x/y/z/a"); 
  
        // create clone object 
        CompositeName cloneComposite 
            = (CompositeName)compositeName.clone(); 
  
        // print CompositeName 
        System.out.println("Clone CompositeName:"
                           + cloneComposite); 
        System.out.print("Members:"); 
        Enumeration<String> enumeration 
            = cloneComposite.getAll(); 
        while (enumeration.hasMoreElements()) 
            System.out.print(enumeration.nextElement() 
                             + ", "); 
    } 
}
輸出:
Clone CompositeName:x/y/z/a
Members:x, y, z, a,

參考文獻:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompositeName.html#clone()




相關用法


注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 CompositeName clone() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。