是否在Java中继承了同步? [英] Is synchronized inherited in Java?
问题描述
我有超类点
和已同步
方法 draw()
。如果我覆盖方法 draw()$ c,
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屋!