Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Define the fields of a class using dynamic data.(META PROGRAMMING)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Fo, post: 3698120"] Dear all, I am trying to parse a textual file into classes. For each line (or 2-3 consecutive lines), there is the definition of an object. The objects are fixed and the structure of the line is also predetermined (space-separated file). I am not using a regular-expression parser or a scanner (like JFlex) because the syntax is pretty easy. An example of line is: "OBJ1 FIELD1 FIELD2 FIELD3 FIELD4 FIELD5" Up to now I explicitly created the classes defining the object and I parsed the content using String.substring(i,j), for each line. It works well but I was wondering if it was possible to: 1. Define the class JIT, I mean given a description of classes with the name of the class, the description of the fields and the indexes of the fields, generate automatically the class.It is a kind of metaprogramming, I suppose. 2.Invoke a method or a field of a class defined by a String [...] Object obj ;// defined somewehere else String nameField="field1"; obj.nameField="AAA"; //this should read obj.field1="AAA" [...] I suppose that it is possible to do it using java.lang.Class.getFields () and then using Fields.set(...) checking if the name of the field is the one I want to change. Is it the correct way? Thank you Fo [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Define the fields of a class using dynamic data.(META PROGRAMMING)
Top