You cannot directly add a new field to a Class
object. There are third-party APIs that you can use to create or modify classes (for example, ASM, BCEL), although they are best avoided because they add more complexity.
As for the second part of your question, you can use the Class
object to go through the fields and examine them.
source share