title: Get all classes with an annotation and add them to a hashMap in android
body: <p>I am not sure if this is possible or not, but I would basically like to be able to easily add new items to a list, just by adding a class with a special annotation. The only example I can think of is kind of what I am currently working on. There are a bunch of "challenges" that a user can complete, currently I have a package in my app for the "challenges" and I would like to be able to just create a new class in that package, give it an annotation with some values, like...</p>
  
  <pre><code>@Challenge(key="new_challenge")
  public class NewChallenge extends Achievement {... }
  </code></pre>
  
  <p>That key would be different for each challenge, it will be the challenge name, then in my code I would like to be able to add them all to a HashMap with that "key" as the hashmap key, so it would be map.add(<em>annotationkey</em>, <em>class</em>); It sounds like it should be possible and doable. I am wondering, if it's possible, if it's the right way to go about doing it, and how can it be done?</p>
  
  <p>EDIT1
  I was able to get the Reflections implemented with gradle, but it is always coming up as empty. There are no annotations found at all. Here is how I have it..</p>
  
  <p>Challenge.java</p>
  
  <pre><code>package com.test.annotationtest.annotations;
  
  import java.lang.annotation.Retention;
  import java.lang.annotation.RetentionPolicy;
  
  @Retention(RetentionPolicy.RUNTIME)
  public @interface Challenge {
    public String key();
  }
  </code></pre>
  
  <p>Then for one of my challenges I have...
  TestChallenge.java</p>
  
  <pre><code>package com.test.annotationtest.challenges
  
  import com.test.annotationtest.R;
  import com.test.annotationtest.annotation.Challenge;
  
  @Challenge(key="test_challenge")
  public class TestChallenge extends Achievement {
    public String name = "Test Challenge";
    public TestChallenge() {}
  }
  </code></pre>
  
  <p>Then in my main activity I have...
  MainActivity.java</p>
  
  <pre><code>package com.test.annotationtest;
  import...
  
  public class MainActivity extends AppCompatActivity {
    public Reflections reflections = new Reflections("com.test"); // have tried "com.test.annotationtest" and "com.test.annotationtest.challenges"
    public static Map&lt;String, Achievement&gt; achievements;
    public static List&lt;String&gt; names = new ArrayList&lt;&gt;();
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      achievements = getClasses();
      //setup recycler view and all that to show achievements
    }
  
    public Map&lt;String, Achievement&gt; getClasses() {
      Set&lt;Class&lt;?&gt;&gt; challengeClasses = reflections.getTypesAnnotatedWith(Challenge.class);
      Log.d("Main Activity", "The Challenges");
      Log.d("MAin Activity", "How many are there? " + Integer.toString(challengeClasses.size());
      //more processing on them;
    }
  }
  </code></pre>
  
  <p>but every time I run the application on my emulator it shows in the logcat..
  Main Activity: The Challenges
  MAin Activity: How many are there? 0</p>
  
  <p>I have 9 classes in the challenges package all annotated with the @Challenge(key="name") in them, but none of them are showing up with the reflections getTypesAnnotatedWith return. The "name" is different for each one. Any help would be appreciated. Thank you.</p>