選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

CloneablePoint.20.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. */
  10. package introduction;
  11. public aspect CloneablePoint {
  12. declare parents: Point implements Cloneable;
  13. public Object Point.clone() throws CloneNotSupportedException {
  14. // we choose to bring all fields up to date before cloning.
  15. makeRectangular();
  16. makePolar();
  17. return super.clone();
  18. }
  19. public static void main(String[] args){
  20. Point p1 = new Point();
  21. Point p2 = null;
  22. p1.setPolar(Math.PI, 1.0);
  23. try {
  24. p2 = (Point)p1.clone();
  25. } catch (CloneNotSupportedException e) {}
  26. System.out.println("p1 =" + p1 );
  27. System.out.println("p2 =" + p2 );
  28. p1.rotate(Math.PI / -2);
  29. System.out.println("p1 =" + p1 );
  30. System.out.println("p2 =" + p2 );
  31. }
  32. }