0

enter image description here enter image description here

as shown in the figure
there is an error at 32 line that says
Node<T>(Object) is not defined because clone() returns an Object data Type

I tried to make another constructor that takes an Object data type then cast it

it removes the first error which lead me to another error which says
the clone() method is not visible
however, i write this line "T extends Cloneable"
any solutions :(

thor
  • 21,418
  • 31
  • 87
  • 173

1 Answers1

0

There is no general way to clone another object in Java. Some specific implementing classes may provide a public clone() method, but there is no guarantee that the type T has such a public clone() method.

In particular, the Cloneable interface does not provide a public clone() method; that may be your misunderstanding. The purpose of Cloneable is not as an interface of objects that provide a public cloning interface, but rather as a marker to indicate to the Object.clone() method (if that is used in the cloning process somehow) whether to throw an exception or not. There is no common base type in Java that indicates the presence of a public clone() method. (You can make such an interface if you wish, but it would only apply to your own types.)

newacct
  • 119,665
  • 29
  • 163
  • 224