是否在Java中继承了同步? [英] Is synchronized inherited in Java?

查看:121
本文介绍了是否在Java中继承了同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有超类已同步方法 draw()。如果我覆盖方法 draw() Point 的子类是否会继承 synchronized $ c>在他们或我必须总是写它?

I have superclass Point and a synchronized method draw(). Will the subclasses of Point inherit synchronized if I override method draw() in them or I have to always write it?

推荐答案

不,你总是要写同步。如果你调用超类的synchronized方法,这当然是一个同步调用。 synchronized 不是方法签名的一部分。

No, you will always have to write synchronized. If you call the synchronized method of the super class this will of course be a synchronized call. synchronized is not part of the method signature.

参见 http://gee.cs.oswego.edu/dl/cpj/mechanics.html ,详细描述来自Doug Lea,Java线程老板(或左右) )。

See http://gee.cs.oswego.edu/dl/cpj/mechanics.html for detailed description from Doug Lea, Java threading boss (or so).

这篇关于是否在Java中继承了同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆