Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Synchronized

 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we cannot declare a method as abstract and synchronized?
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because its better not to do it since its better to synchronize your code at block levels instead of making the whole method as synchronized, however note that when you define a concrete implmentation of the method you can specify that its synchronized.

(peace)
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to make it more clear, if you have an abstract method, then while overriding you can add the synchronized keyword to the method. And if a method is synchronized (non-abstract method of course), then while overriding it, you can remove the synchronized keyword. So there's no point in making an abstract method synchronized as the overriding code can add or remove the synchronized keyword on will. This behavior of the synchronized keyword is because synchronized is not a part of method signature...
 
Prav sharma
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rightly said. SYnchronised is not a part of the method signature.

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15493
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether a method needs to be synchronized or not, depends on how that method is implemented.

Since an abstract method has no implementation at all, it doesn't make sense to make it synchronized.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic