File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract synchronized methods not allowed.

 
Mark Gabb
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Could anyone give me any information on why you can't have an abstract synchronized method like below:
I can't see why you can't do this, and the compiler is not giving me any information?
Also I can't find any useful information on google.



Cheers

Mark
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A thread which enters the synchronized method must get the lock of the object (or of the class) in which the method is defined. You can not instantiate an abstract class so there is no object with the lock.
 
Mark Gabb
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh, I see :-)

I have just realised now that you can override a synchronized method with a non-synchronized version of the method so this would make sense.

Thank you for your help Lukas.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also view it like this: Whether a method needs to be synchronized, really depends on the implementation of the method; it's an implementation detail. An abstract class only declares the interface of abstract methods, and doesn't know anything about the implementation (which is in a concrete subclass of the abstract class). It would be strange if an implementation detail is specified in the interface of a method.

You can use the 'synchronized' modifier on a concrete implementation of an abstract method, which is where it belongs.
 
Mark Gabb
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper Young wrote:You can also view it like this: Whether a method needs to be synchronized, really depends on the implementation of the method; it's an implementation detail. An abstract class only declares the interface of abstract methods, and doesn't know anything about the implementation (which is in a concrete subclass of the abstract class). It would be strange if an implementation detail is specified in the interface of a method.

You can use the 'synchronized' modifier on a concrete implementation of an abstract method, which is where it belongs.


Ok, thank you. :-)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic