0

I have created my own annotation and this annotation receives class.class. The class itself is extending another class.

I am trying to achieve almost the same as using @RunWith(), but instead of running the class I would like to use it to get the class.class in my parent class, so I will not need to send it in a @Before annotation.

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface RunWithClass {
  /** @return the classes to be run */
  Class<?>[] value();
}

@RunWithClass(UnitTests.class)
public class UnitTests extends TestProxy {

and the method within TestProxy 

private void updateClassReference() {
/**
here I would like to get the class in the above case will be  UnitTests
(so I will be able to create an instance of the class for reflection
**/

}
Mikhail Kholodkov
  • 23,642
  • 17
  • 61
  • 78

1 Answers1

0

You can simply get the value of @RunWithClass annotation and use it as below:

Class<?>[] classesToRun = this.getClass().getAnnotation(RunWithClass.class).value();

I can try to give a better answer if you clarify your question.

Bahattin Ungormus
  • 628
  • 1
  • 9
  • 23