Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can a class be synchronized  RSS feed

 
ravisha andar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


Can anybody please let me know why a class cant be synchronized ?

Regards,
Ravisha
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the first problem I can see is that it is not clear how a synchronized class should behave. It is not defined anywhere. If you try to come up with a definition of your own, you might soon get into some trouble (what about static methods, public fields, public static fields etc.)

Secondly, it might not benefit you much. The most naive interpretation of a "synchronized class" is rather easily doable in Java: just make every non-private method synchronized and every non-final field private. In my experience you usually want more sophisticated design, therefore the real use of this "synchronized class" would be very limited anyway.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!