APIメソッドのいくつかがどのように機能するかを理解しようとしています
以下は、java.lang.String クラスの equals メソッドのスニペットです。
コードが実際に 2 つの文字列を比較している方法を教えてください。カウントの意味はわかりますが、オフセットは何を意味しますか。これらの変数はどのように値を取得していますか?
文字列を作成するときのように。これらはどのように初期化されますか。
詳細な行ごとの説明と、インスタンス変数、値、カウント、オフセットなどを初期化する方法とタイミング ??
public boolean equals(Object anObject) {
1014 if (this == anObject) {
1015 return true;
1016 }
1017 if (anObject instanceof String) {
1018 String anotherString = (String)anObject;
1019 int n = count;
1020 if (n == anotherString.count) {
1021 char v1[] = value;
1022 char v2[] = anotherString.value;
1023 int i = offset;
1024 int j = anotherString.offset;
1025 while (n-- != 0) {
1026 if (v1[i++] != v2[j++])
1027 return false;
1028 }
1029 return true;
1030 }
1031 }
1032 return false;
1033 }