What is a good way to test that a Java method is synchronized?

前端 未结 4 426
野趣味
野趣味 2020-12-10 02:29

I have several classes that implement some interface. The interface has a contract, that some methods should be synchronized, and some should not, and I want to verify that

4条回答
  •  遥遥无期
    2020-12-10 03:23

    Using reflection, get the method's Method object, and invoke toString() on it. The "synchronized" keyword should appear in toString()'s output.

提交回复
热议问题