aspose file tools
The moose likes Java in General and the fly likes Using reflection to get the value of a final static field Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Using reflection to get the value of a final static field" Watch "Using reflection to get the value of a final static field" New topic
Author

Using reflection to get the value of a final static field

Struan Kerr
Greenhorn

Joined: Feb 01, 2005
Posts: 10
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
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
Many thanks,

Shows its pays to read more of the javadocs than just the method you're interested in!

Regards

Struan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using reflection to get the value of a final static field
 
Similar Threads
Querying object from a collection
Determine type of a primitive
Generic jtable
different behavior with db2 driver, type 4
Parsing main args OO style