public Font getNewFont(){
  Font nfont =new Font(ofont.getAttributes());  
  return nfont;
}不知行不行试试看:))

解决方案 »

  1.   

    to 微电
    你是否是微硬
    我举的只是一个例子,返回值是我个人作的类,请问如何解决?
    .clone()函数是什么意思?如何解决?
      

  2.   

    你是例子,我也是例子啊,作相应改变不就行了:))要实现.clone()函数你必须实现Cloneable 接口
      

  3.   

    to 小草
    任何的对象,只要运行其.clone()都能得到一个拷贝吗?
    在类的继承过程中,要不要对clone()进行处理?
      

  4.   

    抄段例子自己研究去:))
    class DepthReading implements Cloneable {
      private double depth;
      public DepthReading(double depth) { 
        this.depth = depth;
      }
      public Object clone() {
        Object o = null;
        try {
          o = super.clone();
        } catch(CloneNotSupportedException e) {
          e.printStackTrace(System.err);
        }
        return o;
      }
    }class TemperatureReading implements Cloneable {
      private long time;
      private double temperature;
      public TemperatureReading(double temperature) {
        time = System.currentTimeMillis();
        this.temperature = temperature;
      }
      public Object clone() {
        Object o = null;
        try {
          o = super.clone();
        } catch(CloneNotSupportedException e) {
          e.printStackTrace(System.err);
        }
        return o;
      }
    }class OceanReading implements Cloneable {
      private DepthReading depth;
      private TemperatureReading temperature;
      public OceanReading(double tdata, double ddata){
        temperature = new TemperatureReading(tdata);
        depth = new DepthReading(ddata);
      }
      public Object clone() {
        OceanReading o = null;
        try {
          o = (OceanReading)super.clone();
        } catch(CloneNotSupportedException e) {
          e.printStackTrace(System.err);
        }
        // Must clone references:
        o.depth = (DepthReading)o.depth.clone();
        o.temperature = 
          (TemperatureReading)o.temperature.clone();
        return o; // Upcasts back to Object
      }
    }public class DeepCopy {
      public static void main(String[] args) {
        OceanReading reading = 
          new OceanReading(33.9, 100.5);
        // Now clone it:
        OceanReading r = 
          (OceanReading)reading.clone();
      }
    } ///:~
      

  5.   

    因为我调用的类不是自己做的,协作方要求不修改类
    所以不能对其进行派生,他又没有从Cloneable 派生
    如何解决?
      

  6.   

    to 微电
    jixu
    我使用其它单位做的类,不能修改和派生,但是必须用byval传参,如何实现?