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

前端 未结 4 2140
礼貌的吻别
礼貌的吻别 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 07:08

    For two instances of class X,

    x1.getClass() == x2.getClass()
    

    only if

    x1.getClass().getClassLoader() == x2.getClass().getClassLoader()
    

    Note: Class.getClassLoader() may return null which implies the bootstrap ClassLoader.

提交回复
热议问题