Using reflection to get the value of a final static field
Struan Kerr
Greenhorn
Joined: Feb 01, 2005
Posts: 10
posted
0
I'm writing code to automatically generate database access code. In order to do this it needs to call the stored procedure with parameters extracted from an xml file. I've given each parameter an attribute sqltype which should take the name of one of the fields of java.sql.Types and then I'm using reflection to get the actual value of that field.
Now my problem is that to get the value of the field you need an instance of the class to reflect on, but Types can't be instantiated, so this is my work around, is there a better way?
Thanks
Struan
Jeff Albertson
Ranch Hand
Joined: Sep 16, 2005
Posts: 1780
posted
0
You don't need to instantiate the class because the fields you want are all static, and for static fields, you pass null to methods like getInt.
There is no emoticon for what I am feeling!
Struan Kerr
Greenhorn
Joined: Feb 01, 2005
Posts: 10
posted
0
Many thanks,
Shows its pays to read more of the javadocs than just the method you're interested in!