Cloneable

2021-12-24  本文已影响0人  抬头挺胸才算活着
作者:木女孩
链接:https://www.zhihu.com/question/52490586/answer/130744569
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

#ifdef ASSERT
  // Just checking that the cloneable flag is set correct
  if (obj->is_array()) {
    guarantee(klass->is_cloneable(), "all arrays are cloneable");
  } else {
    guarantee(obj->is_instance(), "should be instanceOop");
    bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
    guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
  }
#endif

  // Check if class of obj supports the Cloneable interface.
  // All arrays are considered to be cloneable (See JLS 20.1.5)
  if (!klass->is_cloneable()) {
    ResourceMark rm(THREAD);
    THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
  }

参考资料:
Java中Cloneable的使用

上一篇 下一篇

猜你喜欢

热点阅读