gpt4 book ai didi

java - 如何堆叠 getClass()

转载 作者:行者123 更新时间:2023-11-30 09:30:06 24 4
gpt4 key购买 nike

为什么第一行有效而第二行无效:

Class<? extends Class> c1                  = (new Object()).getClass().getClass();
Class<? extends Class<? extends Class>> c2 = (new Object()).getClass().getClass().getClass();

最佳答案

来自 Object.getClass 的 API 文档

The actual result type is Class where |X| is the erasure of the static type of the expression on which getClass is called.

所以 (new Object()).getClass()将返回 Class<? extends Object> .我们要调用getClass在那上面。所以 X 将是 Class ,这会给我们 Class<? extends Class> .

关于java - 如何堆叠 getClass(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13429141/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com