2

私は Java の専門家ではありませんが、Java を使用しているときに発生するエラーは通常、理解できます。しかし、この特定のものには頭を悩ませています。

私は次のクラスを持っています(この投稿を読みやすくするために不要な毛羽立ちを取り除きました)

package miui.content.res;

import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.content.res.Configuration;
import android.os.Parcel;
import android.os.RemoteException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class ExtraConfiguration
    implements Comparable<ExtraConfiguration>
{
    public int themeChanged;

    public int compareTo(ExtraConfiguration that)
    {
        return this.themeChanged - that.themeChanged;
    }
}

私には、これはかなり簡単に思えますが、コンパイル時に次のエラーが発生します。

out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/miui/content/res/ExtraConfiguration.java:2: 
name clash: 
    compareTo(java.lang.Object) in miui.content.res.ExtraConfiguration and 
    compareTo(T) in java.lang.Comparable<miui.content.res.ExtraConfiguration> 
    have the same erasure, yet neither overrides the other

消去の概念をブラッシュアップしました。コード スニペットに示す compareTo() メソッドは、ExtraConfiguration クラスで唯一のものです。この時点で、何が問題なのかわかりません。

この特定のクラスは、逆コンパイルされたソースから複製しようとしている MIUI として知られる ROM の Android フレームワークからのものです。それまでの間、私は単純に「implements Comparable」を削除しました

前もって感謝します。

4

2 に答える 2

2

これを回避するためにこれを行うことができるはずですが、エラーが発生する理由を説明できません。

public class ExtraConfiguration
    implements Comparable<Object>
{
    public int themeChanged;

    public int compareTo(Object that)
    {
        if (!(that instanceof ExtraConfiguration)) {
            throw new ClassCastException();
        } else {
            return compareTo((ExtraConfiguration) that);
        }
    }

    public int compareTo(ExtraConfiguration that)
    {
        return this.themeChanged - that.themeChanged;
    }
}
于 2012-08-15T01:56:55.100 に答える
0

署名にを追加してみてください@OverridecompareTo

于 2012-08-15T01:47:09.147 に答える