简体   繁体   中英

Error: The type T cannot be used in GenericTypeMatcher - Expression expected

I tried to implement a generic method that will return a GenericTypeMatcher (provided by AssertJ Swing) of type parameter T. You can see the method here .

The problem is that I get an Expression expected error for the supported type of the GenericTypeMatcher with the Class<T> .

Do you have any idea how to solve it?

The problem here is that GenericTypeMatcher accepts a Class<T> argument.
You're passing the type definition instead, which is invalid.

private static <T extends Component> GenericTypeMatcher<T> getMatcher(final Class<T> clazz) {
   return new GenericTypeMatcher<T>(clazz) {
      @Override
      protected boolean isMatching(final T object) {
         return ...
      }
   }
}

Usage

YourClass.getMatcher(YourComponent.class);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM