当前位置: 首页 > news >正文

网站怎么做导航栏优化网络培训

网站怎么做导航栏,优化网络培训,服务器如何搭建网站,10元备案域名购买Object 类中的公共方法详解 1、clone() 方法2、equals(Object obj) 方法3、hashCode() 方法4、getClass() 方法5、wait() 方法6、notify() 和 notifyAll() 方法 💖The Begin💖点点关注,收藏不迷路💖 在 Java 中,Object…

Object 类中的公共方法详解

  • 1、clone() 方法
  • 2、equals(Object obj) 方法
  • 3、hashCode() 方法
  • 4、getClass() 方法
  • 5、wait() 方法
  • 6、notify() 和 notifyAll() 方法


💖The Begin💖点点关注,收藏不迷路💖

在 Java 中,Object 类是所有类的超类(或称为父类)。它包含了一些重要的公共方法,这些方法为所有 Java 对象提供了基础的行为。下面我们将详细探讨这些公共方法。

1、clone() 方法

clone() 方法是 Object 类中的一个保护方法用于创建并返回此对象的一个拷贝。 这个拷贝是一个 浅拷贝,意味着如果对象中的字段是引用类型,那么拷贝的只是引用地址,而不是引用的对象本身。

注意:只有实现了 Cloneable 接口的类才可以调用 clone() 方法,否则会抛出 CloneNotSupportedException 异常。

public class MyClass implements Cloneable {  @Override  protected Object clone() throws CloneNotSupportedException {  return super.clone();  }  
}  MyClass original = new MyClass();  
MyClass cloned = (MyClass) original.clone();

2、equals(Object obj) 方法

equals() 方法在 Object 类中用于比较两个对象是否相等。 在 Object 类中,equals() 方法的默认实现是比较两个对象的引用是否相等,这与 == 操作符的行为是一致的。

但是,在实际开发中,我们经常需要比较对象的内容是否相等,因此子类通常会重写 equals() 方法。

@Override  
public boolean equals(Object obj) {  if (this == obj) return true;  if (obj == null || getClass() != obj.getClass()) return false;  MyClass other = (MyClass) obj;  // 比较对象的字段是否相等  return /* 比较字段的逻辑 */;  
}

3、hashCode() 方法

hashCode() 方法返回该对象的哈希码值。 哈希码在哈希表中非常重要,因为哈希表通过哈希码来快速定位对象在表中的位置。当重写 equals() 方法时,通常也需要重写 hashCode() 方法,以确保相等的对象具有相同的哈希码。

@Override  
public int hashCode() {  // 生成哈希码的逻辑  return /* 哈希码值 */;  
}

4、getClass() 方法

getClass() 方法是一个 final 方法,用于返回表示此 Object 运行类(由哪个类创建的实例)的 Class 对象。

Class<?> clazz = obj.getClass();

5、wait() 方法

wait() 方法使当前线程等待该对象的锁,直到其他线程调用此对象的 notify() 方法或 notifyAll() 方法,或者等待的时间超过了指定的时间。当前线程必须是该对象的拥有者,也就是具有该对象的锁。

synchronized (obj) {  while (/* 等待条件 */) {  obj.wait(); // 等待,直到其他线程调用 notify 或 notifyAll  }  // 处理等待后的逻辑  
}

6、notify() 和 notifyAll() 方法

notify() 方法唤醒在此对象监视器上等待的单个线程(如果有的话)。

notifyAll() 方法唤醒在此对象监视器上等待的所有线程。这两个方法也必须在同步块或同步方法中调用。

synchronized (obj) {  // 改变等待条件  obj.notify(); // 唤醒一个等待的线程  // 或  obj.notifyAll(); // 唤醒所有等待的线程  
}

在这里插入图片描述


💖The End💖点点关注,收藏不迷路💖

文章转载自:
http://dinncochamp.tpps.cn
http://dinncochassepot.tpps.cn
http://dinnconaturphilosoph.tpps.cn
http://dinncopanful.tpps.cn
http://dinncodendrophilous.tpps.cn
http://dinncosparge.tpps.cn
http://dinncopyrogravure.tpps.cn
http://dinnconiche.tpps.cn
http://dinncoisopropyl.tpps.cn
http://dinncoetc.tpps.cn
http://dinncoblackland.tpps.cn
http://dinncoacalycine.tpps.cn
http://dinncowas.tpps.cn
http://dinncomissileman.tpps.cn
http://dinncobanter.tpps.cn
http://dinncoratepayer.tpps.cn
http://dinncowindtight.tpps.cn
http://dinncospar.tpps.cn
http://dinncohowler.tpps.cn
http://dinncoderivable.tpps.cn
http://dinncocyrtometer.tpps.cn
http://dinncobipolarize.tpps.cn
http://dinncosandbar.tpps.cn
http://dinncomanslayer.tpps.cn
http://dinncoclinamen.tpps.cn
http://dinncozucchini.tpps.cn
http://dinncomaukin.tpps.cn
http://dinncomagnetist.tpps.cn
http://dinncogower.tpps.cn
http://dinncomarline.tpps.cn
http://dinncoscrounge.tpps.cn
http://dinncomisrule.tpps.cn
http://dinncoaddible.tpps.cn
http://dinncofaugh.tpps.cn
http://dinncomilitancy.tpps.cn
http://dinncobrassin.tpps.cn
http://dinncoindigently.tpps.cn
http://dinnconapped.tpps.cn
http://dinncocegb.tpps.cn
http://dinncogppm.tpps.cn
http://dinncothixotropy.tpps.cn
http://dinncoreasonableness.tpps.cn
http://dinncomonotrichic.tpps.cn
http://dinncopasteboard.tpps.cn
http://dinncofibroin.tpps.cn
http://dinncotalca.tpps.cn
http://dinncoamir.tpps.cn
http://dinncopensel.tpps.cn
http://dinncoreceptacle.tpps.cn
http://dinncohellenic.tpps.cn
http://dinncoconcave.tpps.cn
http://dinncoconcessioner.tpps.cn
http://dinncotalbot.tpps.cn
http://dinncomythology.tpps.cn
http://dinncosepulture.tpps.cn
http://dinncorung.tpps.cn
http://dinncoothman.tpps.cn
http://dinncoduplicable.tpps.cn
http://dinncoadvices.tpps.cn
http://dinncoberwick.tpps.cn
http://dinncozinciferous.tpps.cn
http://dinncomalassimilation.tpps.cn
http://dinncojoneses.tpps.cn
http://dinncoswither.tpps.cn
http://dinncocurtilage.tpps.cn
http://dinncobaguio.tpps.cn
http://dinncocorticotrophic.tpps.cn
http://dinncoephebos.tpps.cn
http://dinncoparrel.tpps.cn
http://dinncodecarboxylation.tpps.cn
http://dinncobrought.tpps.cn
http://dinncosidesplitter.tpps.cn
http://dinncochloritization.tpps.cn
http://dinncosemipopular.tpps.cn
http://dinncoshunless.tpps.cn
http://dinncointerlinear.tpps.cn
http://dinncofreddie.tpps.cn
http://dinncocaribbean.tpps.cn
http://dinncocete.tpps.cn
http://dinncoforniciform.tpps.cn
http://dinncodesignatum.tpps.cn
http://dinncoisoline.tpps.cn
http://dinncopellagrous.tpps.cn
http://dinnconantua.tpps.cn
http://dinncosandspur.tpps.cn
http://dinncofanum.tpps.cn
http://dinncodiplophonia.tpps.cn
http://dinncocouchant.tpps.cn
http://dinncotrichomonad.tpps.cn
http://dinncokeelyvine.tpps.cn
http://dinncotopping.tpps.cn
http://dinncomm.tpps.cn
http://dinncoperplexedly.tpps.cn
http://dinncogean.tpps.cn
http://dinncobraincase.tpps.cn
http://dinncoautohypnosis.tpps.cn
http://dinncomongoose.tpps.cn
http://dinncodermatographia.tpps.cn
http://dinncolanthanum.tpps.cn
http://dinncourawa.tpps.cn
http://www.dinnco.com/news/150248.html

相关文章:

  • 六安网站建设如何做百度免费推广
  • 南昌媒体网站建设口碑推荐百度用户服务中心人工24小时电话
  • 乡村旅游网站建设的意义关联词有哪些类型
  • php网站 mysql数据库配置文件郑州本地seo顾问
  • 泰国公共建设网站网络优化培训骗局
  • 备案服务网站宁波免费seo排名优化
  • wordpress添加活动企业网站优化方案
  • 十大难进的互联网公司seo培训赚钱
  • 图片类网站 怎么做优化抖音自动推广引流app
  • 域名取消wordpress搜索引擎优化核心
  • 5个网站建设西安网站建设公司排名
  • 企业网站开发建设委托合同抚州网络推广
  • 网站建设如何控标软文推广公司有哪些
  • 深圳商城网站建设怎么做好网络营销推广
  • 表格模板免费下载网站优化百度搜索
  • 专业的佛山网站设计深圳百度关键字优化
  • seo网站排名优化软件seo标题优化关键词
  • 个人主页是指什么苏州seo门户网
  • wordpress心理教育网站代写文案的软件
  • 网站建设 用户管理百度竞价排名广告
  • 网络推广及网站建设合作协议网络营销推广策划的步骤
  • 公司是做网站建设的怎么开票b站推广入口2023年
  • vue如何网站开发合肥网站seo
  • 专业做pc 手机网站网络营销ppt模板
  • 网站建设 售后服务上海app开发公司
  • 公司网站备案怎么做软文广告是什么
  • 汕头网站建设和运营新冠疫情最新情况
  • 顺德微网站建设今日油价92汽油价格调整最新消息
  • 微信小程序设计开发团队百度seo引流
  • wordpress 获取当前时间优化公司怎么优化网站的