Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

12. Meta-Programming > Java and Reflection

Java and Reflection

Java’s reflection is robust but limited. You can certainly call methods with String representations of their names, but the security manager won’t allow you to define new methods or overwrite existing methods at runtime. You can do some of that with Aspects, but that’s arguably not really Java because it has its own syntax, compiler, etc.

An example of when you might want to use Java’s reflection is for testing private methods. When you are writing code using test-driven development (TDD), you still want to use the protection mechanisms built-in to the language. Using reflection to call the private method is pretty straightforward, but requires lots of syntax.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint