gpt4 book ai didi

java - "this"在这样的类之后如何使用?

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:09:28 25 4
gpt4 key购买 nike

我不太明白关键字 this 在这种情况下是如何使用的。

private void checkForComodification() {
// The this I'm concerned about is the first one
if (CyclicArrayList.this.modCount != this.modCount)
throw new ConcurrentModificationException();
}

最佳答案

你有时在内部类中需要这个。

this 指向内部类实例本身。

MyOuterClass.this 指向包含的类实例。

在您的情况下,这是必要的,因为两个类都有一个 modCount 属性(来自外部类 CyclicArrayList 的属性在此处被隐藏)。

关于java - "this"在这样的类之后如何使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498741/

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