如何将默认方法添加到 Guice 接口

How to add default methods to Guice interface

我有以下界面:

public interface FooFactory {
    Foo create();

    default Foo createWithData(Data data){
        Foo foo = create();
        foo.addData(data);
        return foo;
    }
}

我安装如下:

install(new FactoryModuleBuilder().build(FooFactory.class));

但是,问题是 Guice 用它自己的工厂方法覆盖了我的默认方法。我返回的 Foo 与 create() 中的 Foo 相同(未设置数据)。默认方法永远不会被调用。

现在,这只是一个方便的方法,但我可以告诉 Guice 不要覆盖我的函数吗?

guice-assistedinject 模块有一个错误,用于跳过第 L252. and I found there is no tests to testing 行的 java-8 默认方法此功能。

默认方法在java编译器中既不是bridge方法也不是synthetic方法。然而,它的评论说将 跳过默认方法 。代码应为:

if (isDefault(method)){
  ...
}

您需要自己编写 Provider