mardi 21 juillet 2015

Calling a method with an generic parameter with Java reflection

I need to call this method : public T unwrap(Class iface) from a class that I can't import.

I'm trying to do this :

 Class jbossWrappedSt = Class.forName("org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6");

 Method metodoUnwrap = jbossWrappedSt.getDeclaredMethod ("unwrap", new Class[]{Class.class});
 Object val = metodoUnwrap.invoke (st, new Object[] {PreparedStatement.class});

But fails with a NoSuchMethodException exception:

java.lang.NoSuchMethodException: org.jboss.jca.adapters.jdbc.jdk6.WrappedPreparedStatementJDK6.unwrap(java.lang.Class)

Class javadoc : http://ift.tt/1SztE7F





Aucun commentaire:

Enregistrer un commentaire