views:

88

answers:

2

Let us say Java didn't have annotations. What would be the ideas you would come up with to design something like Google Guice's DI framework? I am fairly new to Java and cannot think of anything other than

  • what Junit3 Had
  • XML Configuration
  • Some kind of introspection?

How would you inspect the elements that needed to be injected? What would be your ideal way of configuration other than annotations?

+1  A: 

The popular Plexus IoC(similar to Spring) uses Commons Attributes to provide annotations like metadata via special javadoc comments. This allows it the ability to work on older JVM(pre 1.5 that didn't support annotations while still reaping some of their benefits).

Btw JUnit 3 had nothing like this - it simply enforced a naming scheme for the tests - each test method had to be named "testSomething" so that it would recognized as a test and executed by JUnit. This is technique commonly referred as "convention over configuration".

Bozhidar Batsov
+3  A: 

Before annotations were part of the language, we had XDoclet. It exposes the same power of annotations, but via Javadoc tags. Old-school annotation-driven EJBs had tags like these:

/**
 * @ejb.bean
 *     name="bank/Account"
 *     type="CMP"
 *     jndi-name="ejb/bank/Account"
 *     local-jndi-name="ejb/bank/LocalAccount"
 *     primkey-field="id"
 */
Jesse Wilson