にintValue()を使用することができます。 私はintValueメソッドに書きたいと思った:は、どのように私は私が大学で持っているジェネリッククラス
int i = x.IntValue();
int j = y.IntValue();
return "(" i "、" j ")";
EDIT:問題を解決しました。誰かが正しいかどうかを確認してください:
public class Zahl<T> {
public Integer x;
public Integer y;
public Zahl(Integer x, Integer y) {
this.x = x;
this.y = y;
}
public String intValue() {
int i = this.x.intValue();
int j = this.y.intValue();
return "(" + i + "," + j + ")";
}
}
EDIT 2:問題が解決しました!
class Zahl<N extends Number> {
N x;
N y;
Zahl(N x, N y) {
this.x = x;
this.y = y;
}
String intValue() {
return "(" + x.intValue() + "," + y.intValue() + ")";
}
public class Test {
public static void main(String[] args) {
Zahl<Integer> z = new Zahl<>(7, 8);
System.out.println(z.intValue());
}
}
出力::(7,8)
は非常に悪い考えです。 .. "N"または "T"だが、整数ではない。 – assylias
'return"( "+ i +"、 "+ j +") "を試してください; –
' '最初の行に?あなたは本当にジェネリック医薬品を関与させたいですか?もしそうなら、あなたはどんな結果を探していますか? –
slim