当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。