java.lang.CloneNotSupportedException: com.lbh.xxmanager.basic.alg.Node at java.lang.Object.clone
阿新 • • 發佈:2021-02-10
技術標籤:異常javabugobjectjdkCloneNotSupport
問題描述:
使用Object的clone方法報錯
該行程式碼報錯
node = (Node) curr.clone();
java.lang.CloneNotSupportedException: com.lbh.xxmanager.basic.alg.Node
at java.lang.Object.clone(Native Method)
<hr style=" border:solid; width:100px; height:1px;" color=#000000 size=1">
原因分析:
* The class {@code Object} does not itself implement the interface
* {@code Cloneable}, so calling the {@code clone} method on an object
* whose class is {@code Object} will result in throwing an
官方註釋,該類沒有繼承Cloneable介面,所以會丟擲CloneNotSupportedException。
解決方案:
繼承Cloneable介面
public class Node implements Cloneable