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 6326695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:08:22+00:00 2026-05-24T17:08:22+00:00

When trying to get JPA annotations at runtime for some properties, I encountered this

  • 0

When trying to get JPA annotations at runtime for some properties, I encountered this problem. I can’t explain why.

PS: after a debugging session with Spring, I found the explanation of this problem: bridged methods that are introduced at compile time by the compiler. Please see my own answer to this question..

Here is a sample source code replicating the issue (simplified version of real code).

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.io.Serializable;
import java.lang.reflect.Method;

public class MethodMasking {

public interface HasId<ID extends Serializable>  {
    void setId(ID id);
    ID getId();
}

public interface Storeable extends HasId<Long> {}

class Item implements Storeable {Long id; String code;
    Item(Long id, String code) { this.id = id; this.code = code; }
    public Long getId() { return id; }
    public void setId(Long id) {this.id = id;}
}

public static void main(String[] args) throws IntrospectionException {
    final BeanInfo beanInfo = Introspector.getBeanInfo(Item.class);

    java.lang.System.out.println("BeanInfo:methodDescriptors:");
    final MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
    for (MethodDescriptor methodDescriptor : methodDescriptors) {
        java.lang.System.out.println("\t"+methodDescriptor.getMethod().getName());
    }

    java.lang.System.out.println("class:declaredMethods:");
    final Method[] declaredMethods = Item.class.getDeclaredMethods();
    for (Method declaredMethod : declaredMethods) {
        java.lang.System.out.println("\t"+declaredMethod.getName());
    }
}

}
Output of the program:

BeanInfo:methodDescriptors:
    hashCode
    wait
    getId
    notifyAll
    equals
    wait
    wait
    toString
    setId
    notify
    setId
    getClass
class:declaredMethods:
    getId
    getId
    setId
    setId

Now I’m confused:
why in beanInfo there are 2 methods descriptors for setId but only one for getId ?
why in declared method there are 2 methods for getId and 2 methods for setId ?

While debugging I have these methods signatures when using the getDeclaredMethods :

[0] = {java.lang.reflect.Method@139}"public java.lang.Long MethodMasking$Item.getId()"
[1] = {java.lang.reflect.Method@446}"public java.io.Serializable MethodMasking$Item.getId()"
[2] = {java.lang.reflect.Method@447}"public void MethodMasking$Item.setId(java.lang.Long)"
[3] = {java.lang.reflect.Method@448}"public void MethodMasking$Item.setId(java.io.Serializable)"

Edit:
After some tests I have found that the cause of the problem is the usage of generics in the HasId interface…

Declared this way, the problem disapear: no more duplicate methods.

public interface HasId  {
        void setId(Long id);
        Long getId();
    }

    public interface Storeable extends HasId {} 
  • 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-24T17:08:24+00:00Added an answer on May 24, 2026 at 5:08 pm

    It is because the compiler is introducing bridge methods when Generics are used:
    some explanation here

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

Sidebar

Related Questions

Trying to get comfortable with jQuery and I have encountered some sample code that
I'm using Spring with Hibernate as a JPA provider and are trying to get
Trying to get my css / C# functions to look like this: body {
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {
Trying to get my mind around google protobuf. I found some implementation of protobuf
I have a Spring/JPA/Hibernate application and am trying to get it to pass my
I'm trying to use PostgreSQL as the database for Hibernate/JPA. However, I get an
I'm trying to wire up Spring Data JPA objects manually so that I can
I'm trying to set up a foreign key relationship with JPA annotations and generate

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.