author | Chengsong |
Fri, 26 May 2023 08:09:30 +0100 | |
changeset 646 | 56057198e4f5 |
parent 44 | a751aa1ee4f7 |
permissions | -rw-r--r-- |
44 | 1 |
package Main |
2 |
||
3 |
object CompoundClasses { |
|
4 |
trait Cloneable extends java.lang.Cloneable { |
|
5 |
override def clone(): Cloneable = { super.clone(); this } |
|
6 |
} |
|
7 |
||
8 |
trait Resetable { |
|
9 |
def reset: Unit |
|
10 |
} |
|
11 |
||
12 |
def cloneAndReset(obj: Cloneable with Resetable): Cloneable = { |
|
13 |
val cloned = obj.clone() |
|
14 |
obj.reset |
|
15 |
cloned |
|
16 |
} |
|
17 |
} |
|
18 |