The compiler does not do this for you, because it can not know if accessing any member is truly thread-safe. You might share the logFile with other instances of Foo. This would be a case where the compiler would wrongly remove the shared from this, if it would do so automatically inside synchronized blocks.

Makes sense; thank you!

Reply via email to