Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6993259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:44:30+00:00 2026-05-27T19:44:30+00:00

I am trying to do reverse lookup on few enum classes implementing same Field

  • 0

I am trying to do reverse lookup on few enum classes implementing same Field interface by iterating through list of Classes using Guava’s Maps.uniqueIndex:

  Field valueOfSearchName = null;
  for (final Class<? extends Enum<?>> clazz : ImmutableList.of(
      EntityField.class,
      AddressField.class,
      PersonFunctionType.class)) {
    valueOfSearchName = Fields.valueOfSearchName(clazz, term.field()); // error
    if (valueOfSearchName != null) {
      // do something...
      break;
    }
  }

I don’t want to repeat same code (for making index and doing lookup) in all enum classes, so I use helper static class Fields containing Fields.valueOfSearchName method:

  public static <E extends Enum<E> & Field> Field valueOfSearchName(
      final Class<E> clazz, final String searchName) {
    // TODO: cache the index
    final ImmutableMap<String, E> index = Maps.uniqueIndex(
        EnumSet.allOf(clazz), GET_SEARCH_NAME_FUNCTION);
    return index.get(searchName);
  }

Unfortunately, Eclipse shows an error:

Bound mismatch: 
The generic method valueOfSearchName(Class<E>, String) of type Fields is not 
applicable for the arguments (Class<capture#1-of ? extends Enum<?>>, String).
The inferred type capture#1-of ? extends Enum<?> is not a valid substitute
for the bounded parameter <E extends Enum<E> & Field>

The problem is Class<? extends Enum<?>> clazz in for-each loop (not matching Field), but I don’t know how to deal with this case (obviously I cannot add & Field to clazz).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:44:31+00:00Added an answer on May 27, 2026 at 7:44 pm

    Inspired by Tom Hawtin’s answer I created wrapper class holding Classes, but only those with signature <E extends Enum<E> & Field>:

    public final static class FieldEnumWrapper<E extends Enum<E> & Field> {
      private final Class<E> clazz;
      private final ImmutableMap<String, E> index;
    
      public static <E extends Enum<E> & Field> 
          FieldEnumWrapper<E> of(final Class<E> clazz) {
        return new FieldEnumWrapper<E>(clazz);
      }
    
      private FieldEnumWrapper(final Class<E> clazz) {
        this.clazz = clazz;
        this.index = Maps.uniqueIndex(
            EnumSet.allOf(clazz), new Function<E, String>() {
              @Override
              public String apply(final E input) {
                return input.searchName();
              }
            });
      }
    
      public Class<E> clazz() {
        return clazz;
      }
    
      public Field valueOfSearchName(final String searchName) {
        return index.get(searchName);
      }
    }
    

    Now:

    for (final FieldEnumWrapper<?> fieldEnum : ImmutableList.of(
        FieldEnumWrapper.of(EntityField.class),
        FieldEnumWrapper.of(AddressField.class),
        FieldEnumWrapper.of(PersonFunctionType.class))) {
      valueOfSearchName = fieldEnum.valueOfSearchName("POD_I_OS_PARTNER");
      // ...
    

    is type-safe and inappropriate usage of FieldEnumWrapper‘s static factory:

    FieldEnumWrapper.of(NotEnumAndFieldClass.class)
    

    generates compile error.

    Moreover, valueOfSearchName is now method of FieldEnumWrapper what make more sense that helper class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to reverse dns a list of IPs using socket.gethostbyaddr() in python,
I'm currently trying to reverse geocode a series of lat/long co-ordinates using the Virtual
Im trying to reverse the order of the following linked list, I've done so,
I am trying to reverse a C style string using the following simple program.
I am trying to reverse engineer pojos (using hibernate tools plugin v3.2.4x in eclipse
I am trying to parse out a Reverse Geo-location using Bing Maps. http://www.microsoft.com/maps/isdk/ajax/ Find
First time using PyUSB, trying to reverse engineer an eye-toy (Play Station) for OS
Context I'm learning C, and I'm trying to reverse a string in place using
I'm trying to do a reversed SQL lookup using Django 1.3. I found a
I am trying to reverse a linked list. This is the code I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.