You can create interface CustomCloneable
:
interface CustomCloneable {
public CustomCloneable clone();
}
And use it in your situation. Note that you will have to provide clone implementation for your classes or use methods/libraries described below.
class Queue<E extends CustomCloneable>
And after that you can call clone
method on your
public Elem(E v) {
val = (E) v.clone();
}
On the other hand you might be looking for sth else. Refer here for other options and why you should avoid cloning.
Instead of that use some other options, like apache-commons [
SerializationUtils
][1] (deep-clone) orBeanUtils
(shallow-clone), or simply use a copy-constructor.
Also please read java code conventions