Java 中的synchronized 是继承的吗? [英] Is synchronized inherited in Java?
问题描述
我有超类 Point
和一个 synchronized
方法 draw()
.Point
的子类是否会继承 synchronized
如果我覆盖它们中的方法 draw()
或者我必须始终编写它?
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 中的synchronized 是继承的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!