Why is choosing a BiConsumer type for an instance method with one argument different in this case?

I am trying to compile this piece of code:

import java.util.Collection;
import java.util.function.BiConsumer;
import de.hybris.platform.servicelayer.exceptions.ModelSavingException;
import de.hybris.platform.servicelayer.model.ModelService;

public class Foo {

    public static interface ModelService2 {
        public abstract void saveAll(Object[] paramArrayOfObject) throws ModelSavingException;
        public abstract void saveAll(Collection<? extends Object> paramCollection) throws ModelSavingException;
        public abstract void saveAll() throws ModelSavingException;
    }

    public void bar() {
        final BiConsumer<ModelService2, Collection<? extends Object>> consumer1 = ModelService2::saveAll;
        final BiConsumer<ModelService, Collection<? extends Object>> consumer2 = ModelService::saveAll;
    }
}

The interface is ModelServicedefined by the SAP hybris platform. ModelService2simply replicates overloaded methods with the name saveAlldefined in the hybris platform interface.

I get the following compiler error while compiling above:

1. ERROR in src\Foo.java (at line 17)
    final BiConsumer<ModelService, Collection<? extends Object>> consumer2 = ModelService::saveAll;
                                                                             ^^^^^^^^^^^^^^^^^^^^^
Cannot make a static reference to the non-static method saveAll(Object[]) from the type ModelService

Why does the compiler execute a different type of output for ModelServicewhen the only difference I can determine is where each of the interfaces are located?

I am using javac 1.8.0_77 to compile in this case. For example, Eclipse does not report any errors for the above code.

EDIT:

A similar error also occurs for the following variable declarations:

final Consumer<ModelService2> consumer3 = ModelService2::saveAll;
final Consumer<ModelService> consumer4 = ModelService::saveAll;

Compilation error in this case:

1. ERROR in src\Foo.java (at line 19)
    final Consumer<ModelService> consumer4 = ModelService::saveAll;
                                             ^^^^^^^^^^^^^^^^^^^^^
Cannot make a static reference to the non-static method saveAll(Object[]) from the type ModelService

EDIT2:

:

'-noExit'
'-classpath'
'<classpath>'
'-sourcepath'
'<source path>'
'-d'
'<path>\classes'
'-encoding'
'UTF8'

3:
3 , Eclipse:

  // Method descriptor #43 (Ljava/util/Collection;)V
  // Signature: (Ljava/util/Collection<+Ljava/lang/Object;>;)V
  public abstract void saveAll(java.util.Collection arg0) throws de.hybris.platform.servicelayer.exceptions.ModelSavingException;

  // Method descriptor #45 ([Ljava/lang/Object;)V
  public abstract void saveAll(java.lang.Object... arg0) throws de.hybris.platform.servicelayer.exceptions.ModelSavingException;

  // Method descriptor #10 ()V
  public abstract void saveAll() throws de.hybris.platform.servicelayer.exceptions.ModelSavingException;

:

eclipse java v4.4.1. v4.5.1. , eclipse hybris .

+4
1

, varargs , , Java. , .

:

ModelService vararg saveAll. - saveAll . , ModelService Collection, BiConsumer<ModelService2, Collection<? extends Object>>.

- , , , , . .

ModelService2.saveAll, , vararg ModelService Collection. - , .

Eclipse 4.5.2 javac 1.8.0_77, . , .

+3

All Articles