紳士:
申し訳ありませんが不明確な質問のための私たちが必要とする理由私は本当に失われていますisPrimitive()
)(悲しい顔をここで、私は(私はそれを必要とするとき申し訳ありません、私はちょうどそれを使用することはできませんそれを使用することはできませんので、最初の場所で。
ここにある記事を読んだ後、私はサムスとしての使用法を見つけました
int.class.isPrimitive()
しかし、私は何かをしたいのですが
boolean isTrue = true;
System.out.println(isTrue.class.isPrimitive());
System.out.println(Boolean.valueOf(isTrue).getClass().isPrimitive());
私は、オブジェクトのフィールドを横断しながら、種類をチェックしようとしています。私が今できることにあります
private static boolean isPrimitiveWrapper(Object obj) {
return obj.getClass() == Boolean.class ||
obj.getClass() == Byte.class ||
obj.getClass() == Character.class ||
obj.getClass() == Short.class ||
obj.getClass() == Integer.class ||
obj.getClass() == Long.class ||
obj.getClass() == Float.class ||
obj.getClass() == Double.class;
}
しかし、周りのチェックした後、私はそれで何か間違っているがあるはずだと思うが、私はそれが何であるかを知りません。
そのための任意のユースケースは、実際には理解されるであろう。)
私はあまりにも偏執的ではないことをしようとしています...すでにかなり努力して
ジョープEggen:
プリミティブ型は、いくつかのケースでのオブジェクトとして扱うことができないとして、配列のように、それは最初の識別器としていいです。
Object cloneObject(Object obj) {
Class<?> type = obj == null ? Object.class : obj.getClass();
if (type.isArray()) {
Class<?> elemType = type.getComponentType();
if (!elemType.isPrimitive()) {
Object[] copy = ...
} else {
// Must distinguish between int/double/boolean/...
... int[] ... double[] ...
}
}
Object inta = new int[] { 2, 3, 5, 7 };
int[] pr = (int[]) cloneObject(inta);