using synchronized

Hi all
is it allowed to use static key in the synchronized block and is the answer is yes is it allowed to use empty string?

public class A
{
       private static key = ""
       
       public A() {
            synchronized (key) {
                    ............
            }
       }
}
dannyshAsked:
Who is Participating?
 
TimYatesCommented:
yes, yes
0
 
TimYatesCommented:
>  is it allowed to use empty string

the empty string is still a string object, and synchronized ties to an object, not neccesarially a string with any meaning (or an integer with any value)...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.