简体   繁体   English

这个C#泛型方法模式的等效Java实现是什么

[英]What's the equivalent Java implementation of this C# generic method pattern

I am re writing a library originally written in C# into Java and am trying my best to follow it as closely as possible. 我正在用C#编写一个最初用Java编写的库,我正尽力尽可能地遵循它。 This, however, has me stumped. 然而,这让我很难过。

This is the C# method I want to recreate in Java 这是我想用Java重新创建的C#方法

public T With<TV>(Func<T, IEditable> func, TV value)
        {
            var pageElement = func(TypedThis);
            pageActions.Add(new WebDriverValuePageAction<TV>(pageElement, value));
            return TypedThis;
        }

This is a generic method which is used as part of a Selenium Page Object framework where T is a BasePage and the Method takes any page element inheriting the IEditable interface. 这是一个通用方法,用作Selenium Page Object框架的一部分,其中T是一个BasePage,而Method接受任何继承IEditable接口的页面元素。

What is stumping me is the With<TV> part of the method and how to recreate this in Java. 令我感到困惑的是方法的With<TV>部分以及如何在Java中重新创建它。 Everything else is pretty much done. 其他一切都已完成。 I have been able to recreate T but cannot work out how to also pass in TV (essentially a generic value) along with the function. 我已经能够重新创建T但是无法确定如何在功能中传递电视(基本上是通用值)。

Direct equivalent will be 直接等价物将是

    public <TV> T With(Function<T, IEditable> func, TV value)
    {
        IEditable pageElement = func.apply(TypedThis);
        pageActions.Add(new WebDriverValuePageAction<TV>(pageElement, value));
        return TypedThis;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM