'BiConsumer method reference implementation accept methods list differ from anonymous class implementation

I am trying to get all accept methods from BiConsumer implementation.

I have two classes

class ADto {
    private BDto b;

    public void setB(BDto b) {
        this.b = b;
    }
}
class BDto {
}

I create 2 implementations of BiConsumer<ADto, BDto>:

  1. Anonymous class

    BiConsumer<ADto, BDto> biConsumer = new BiConsumer<>() {
                @Override
                public void accept(ADto aDto, BDto b1) {
                    aDto.setB(b1);
                }
            };
    
  2. Method reference

    BiConsumer<ADto, BDto> biConsumer = ADto::setB;
    

In the first case, I get

public void com.company.Main$1.accept(com.company.ADto,com.company.BDto)
public void com.company.Main$1.accept(java.lang.Object,java.lang.Object)

In the second:

public void Main$$Lambda$14/0x0000000800c02918.accept(java.lang.Object,java.lang.Object)

Why is it working this way?

Method reference equals anonymous class implementation (I also can replace them to each other within IntelliJ hints), but the list of declared methods is different for these two implementations.

I wanted to pass many method references and get parameter types from methods but implementation by anonymous class much larger then by method reference.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source