Does Java guarantee that Object.getClass() == Object.getClass()?

前端 未结 4 2136
礼貌的吻别
礼貌的吻别 2020-11-27 06:41

I really do mean identity-equality here.

For example, will the following always print true?

System.out.println(\"foo\".getClass() ==         


        
4条回答
  •  迷失自我
    2020-11-27 06:58

    Yes.

    The returned Class object is the object that is locked by static synchronized methods of the represented class.

    If it was possible to return multiple instances, then

    public static synchronized void doSomething() {..}
    

    would not be thread-safe.

提交回复
热议问题