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

  • Home
  • SEARCH
  • 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 8544111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:28:30+00:00 2026-06-11T12:28:30+00:00

I have the following code, with a generic ITest interface extended by a not

  • 0

I have the following code, with a generic ITest interface extended by a not generic ITestDouble interface. The op method is overridden by ITestDouble.

When I try to list all the methods of ITestDouble, I get op twice. How can I verify that they are actually the same method?

public class Test {

    public static void main(String[] args) throws NoSuchMethodException {
        for (Method m : ITestDouble.class.getMethods()) {
            System.out.println(m.getDeclaringClass() + ": " + m + "(bridge: " + m.isBridge() + ")");
        }
    }

    public interface ITestDouble extends ITest<Double> {
        @Override
        public int op(Double value);

        @Override
        public void other();
    }

    public interface ITest<T extends Number> {
        public int op(T value);

        public void other();
    }
}

Output:

interface Test$ITestDouble: public abstract int Test$ITestDouble.op(java.lang.Double)(bridge: false)
interface Test$ITestDouble: public abstract void Test$ITestDouble.other()(bridge: false)
interface Test$ITest: public abstract int Test$ITest.op(java.lang.Number)(bridge: false)

PS I know this is the same question as Java Class.getMethods() behavior on overridden methods, but that question got no real answer: the isBridge() call always returns false.

EDIT:
I’m also fine with any library which would do the dirty job of filtering out the “duplicate” op method for me.

  • 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-06-11T12:28:31+00:00Added an answer on June 11, 2026 at 12:28 pm

    Unfortunately you cannot have that information, because as far as the JVM is concerned, ITestDouble has a legitimate method op(Number) which can be totally independent of op(Double). It is actually your Java compiler that makes sure the methods always coincide.

    That implies that you can create pathological implementations of ITestDouble with totally different implementations for op(Number) and op(Double) by using a pre-JDK5 compiler, or a dynamic proxy:

    public static void main(String[] args) throws NoSuchMethodException {
    
        final Method opNumber = ITest.class.getMethod("op", Number.class);
        final Method opDouble = ITestDouble.class.getMethod("op", Double.class);
        final Method other = ITestDouble.class.getMethod("other");
    
        ITestDouble dynamic = (ITestDouble) Proxy.newProxyInstance(
                ITestDouble.class.getClassLoader(),
                new Class<?>[]{ITestDouble.class},
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
                        if (opDouble.equals(m)) return 1;
                        if (opNumber.equals(m)) return 2;
                        // etc....
    
                        return null;
                    }
                });
    
        System.out.println("op(Double): " + dynamic.op(null);            // prints 1.
        System.out.println("op(Number): " + ((ITest) dynamic).op(null);  // prints 2. Compiler gives warning for raw types
    }
    

    EDIT:
    Just learned of Java ClassMate. It is a library that can correctly resolve all type variables in a declaration. It is very easy to use:

        TypeResolver typeResolver = new TypeResolver();
        MemberResolver memberResolver = new MemberResolver(typeResolver);
    
        ResolvedType type = typeResolver.resolve(ITestDouble.class);
        ResolvedTypeWithMembers members = memberResolver.resolve(type, null, null);
        ResolvedMethod[] methods = members.getMemberMethods();
    

    Now if you iterate over methods you’ll see the following:

    void other();
    int op(java.lang.Double);
    int op(java.lang.Double);
    

    Now it is easy to filter for duplicates:

    public boolean canOverride(ResolvedMethod m1, ResolvedMethod m2) {
        if (!m1.getName().equals(m2.getName())) return false;
    
        int count = m1.getArgumentCount();
        if (count != m2.getArgumentCount()) return false;
    
        for (int i = 0; i < count; i++) {
            if (!m1.getArgumentType(i).equals(m2.getArgumentType(i))) return false;
        }
    
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which builds a Generic List of Abc from a
I have following code that populates a System.Collections.Generic.List I don't like it so I
I have the following code implementation of my generic singleton provider: public sealed class
I have the following code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace
I have following code for loading image from url in xml parsing endElement method
I have the following generic code: public V put(K key, V value){ Object o
I have the following code that produces a compilation issue in my C# generic
i have the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using
i have the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using
I have following code public interface IEntity { int Id { get; set; }

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.