0
У меня есть этот код:Использование функций интерфейса в способе общего типа возвращаемого с одной строкой
public class FunctionTest {
public Double getDouble(Function<Integer, Double> function) {
function = t -> Double.valueOf(t);
return function.apply(???); //not sure how to implement this
}
public Function<Integer, Double> getFunction(Integer t) {
return r -> Double.valueOf(t); // not able to fetch value from this as the return type is Function
}
public static void main(String[] args) {
Function<Integer, Double> f = t -> Double.valueOf(t); // works fine
System.out.println(f.apply(4)); // how to aechive this using method?
System.out.println(f);
}
}
Если вы видите t -> Double.valueOf(t)
отлично работает с комбинацией f.apply(4)
теперь вопрос в том, как разработать метод же я попытался два метода, но не удалось.
Пожалуйста, помогите мне в этом.
вы можете упростить ваш 'getFunction()' в ' return Double :: valueOf' – Ash
Спасибо, что очень удобно :) – user7036414