以下のコードを参照してください。Java - 宣言クラスとクラスオブジェクトの違い(クラスとクラス)
public class c1
{
//....
}
Class c2 = obj.getClass();
Object o1 = new c1();
Object o2 = new c2(); // <<----- here
どうしたのですか?
どのように私はc2のオブジェクトを作成できますか?
編集:
int[] s1 = new int[]{4,5,6};
char[] s2 = new char[]{'a'.'b'};
Integer[] new = convertPrimitiveArrayToObject(new Object[]{s1});
Character[] new = convertPrimitiveArrayToObject(new Object[]{s2});
public static <T> T[] convertPrimitiveArrayToObject(Object[] primitive)
{
Object x = primitive[0];
Class type = x.getClass().getComponentType(); // => int OR char
type[] x2 = (type[]) x; // I need to convert array to (int/char/...)
//......
}
あなたはリフレクションを使用する必要が
あなたは 'obj.getClass()'の後に 'new c2'できることを期待していますか? – ChiefTwoPencils
'c2'はクラスではありません。クラス型のオブジェクトです。 – Batty
パラメータ 'Object [] primitive'では' int [] 'または' char [] '配列を渡すことはできません。たぶんあなたは達成したいものの例を提示するべきです。 – SubOptimal