長い間、私はコードを動作させようとしてきましたが、それは不可能です。私が持っているクラスには、整数に設定したジェネリックが必要です。だから私は次のことを試しました:
public class a<T> //set generics for this function
{
private T A;
protected boolean d;
public a(final T A)
{
this.A = A;
//do calculations
//since constructor cannot return a value, pass to another function.
this.d = retnData(Integer.parseInt(A.toString()) != 100); //convert to an integer, the backwards way.
}
private boolean retnData(boolean test)
{
return test;
}
}
// IN ANOTHER CLASS
transient a<Integer> b;
boolean c = b.d = b.a(25); // throws an erorr: (Int) is not apporpriate for a<Integer>.a
両方とも同じデータを受け入れますが、java は int != Integer を認識するため、Java はこれを許可しません。ジェネリックが機能する方法のため、abを設定できません。型 int のプリミティブ性のためです。「型エラー」がスローされるため、整数へのキャストでさえ機能しません。
最後に、これに対して何らかの回避策があるかどうかを尋ねなければなりませんか、それともこれを機能させようとしても無駄ですか?