Reflection using Primitive types

Hi all,

I need to call a method using reflection which takes and array of primitive double objects and I am getting a class cast exception. I am using a convertTypes method to try to return a double[] class. I know primitives are not classes in Java so how can I achieve this?

Method method = collectionClass.getMethod("setAll"+columnNames[i], convertTypes(columnTypes[i]));

method.invoke(this, columnValues[i]);

private Class[] convertTypes(Object columnType){

String colType = (String)columnType;

if (colType.equalsIgnoreCase("int"))

{

returnnew Class[]{Integer.class};

}

elseif (colType.equalsIgnoreCase("float"))

{

returnnew Class[]{double[].class};

//return new Double[]{Double.TYPE};

//return double[].class;

//return double[].class;

}

elseif (colType.equalsIgnoreCase("varchar"))

{

returnnew Class[]{String[].class};

}

returnnull;

}

[2105 byte] By [java_swing_dudea] at [2007-11-27 6:53:21]
# 1

Please clarify, do you need an array of Class objects or a Class object representing the correct array type?

If you need the latter you can use:private Class<?> getArrayClass(String colType) {

if (colType.equalsIgnoreCase("int")) return int[].class;

if (colType.equalsIgnoreCase("float")) return float[].class;

if (colType.equalsIgnoreCase("varchar")) return String[].class;

return null;

}

dwga at 2007-7-12 18:28:04 > top of Java-index,Java Essentials,Java Programming...
# 2
does this help you? i didnt read your question. http://java.sun.com/j2se/1.4.2/docs/api/java/lang/reflect/Array.html
TuringPesta at 2007-7-12 18:28:04 > top of Java-index,Java Essentials,Java Programming...