By Alvin Alexander. Last updated: November 24, 2022
Today I was working with a Java class that extended the Spring class NamedParameterJdbcDaoSupport, and when I went to use the getNamedParameterJdbcTemplate().queryForObject() method, the third parameter of the method required a Class reference. When you see a method like this that requires a Class reference -- and in my case I needed to use a String class -- you just need to pass it in like this:
java.lang.String.class
To be more specific, my method call looked like this:
getNamedParameterJdbcTemplate().queryForObject(
mySqlString,
myParamSource,
java.lang.String.class
)
Any time you see a method call that requires a Class reference, that's all you have to do: pass in the fully-qualified name of the class with the extra .class string at the end.

