|
From: Guillaume P. <gpo...@sy...> - 2007-05-16 00:10:48
|
You can avoid it with a static factory method, e.g. :
|public class GenericsTest<T> {
public static <T> GenericsTest<T> create(Class<T> clazz) {
return new GenericsTest<T>(clazz);
}
public GenericsTest(Class<T> clazz) { }
public T get() { return null; };
public static void main(String[] args) {
String s = create(String.class).get();
System.out.println(s);
}
}|
This way the generic type is inferred by the parameter type.
Guillaume
Thomas Risberg wrote:
> I've added named parameter support to the SimpleJdbcTemplate . Combining
> this with the ParameterizedBeanPropertyRowMapper, that I committed
> recently, and the BeanPropertySqlParameterSource we can now retrieve and
> store JavaBeans(TM) to the database without having to write custom code
> to populate or retrieve the bean property values.
>
> Here is an example:
>
> Customer cust = simpleJdbcTemplate.queryForObject(
> "select id, customer_number, name from customer where id
> = :id",
> new
> ParameterizedBeanPropertyRowMapper<Customer>(Customer.class),
> new MapSqlParameterSource().addValue("id", 5L));
>
> cust.setName("Thomas");
>
> int rows = simpleJdbcTemplate.update(
> "update customer set name = :name where id = :id",
> new BeanPropertySqlParameterSource(cust));
>
>
> I added the named parameter methods to the existing SimpleJdbcTemplate
> class rather than creating a new SimpleNamedParameterJdbcTemplate
> class. If you think this would be better split up, let me know.
>
> If anyone can come up with a better way of instantiating this:
> ParameterizedBeanPropertyRowMapper<Customer>(Customer.class) - then that
> would be great, I haven't found a way of avoiding specifying Customer
> twice there due to the type erasure.
>
>
> Thomas
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
|