The JUnit method counter counts the compareTo method twice. What for?

I am working on a Java Springframework project and using JUnit4 to test it.

My class implements Comparable and overrides the compareTo method.

In my test, when I do

@Test
Class<myClass> m = myClass.class;
Method[] methods = m.getDeclaredMethods();
assertEquals(5, methods.length); 

This test fails , although there are exactly 5 methods in myClass . When I looked in the Eclipse debugger, I see that the compareTo method is called twice.

I can not find an explanation for this behavior. Why is this happening?

+3
source share
1 answer

The compiler generates a bridge method for compareTo()

The mechanism is explained very well in Angelika Langer Generics Frequently Asked Questions: What is the Bridge Method? :

What is a bridge method?

, . , . .

+5

All Articles