有没有办法打印功能界面?

Maz*_*ion 7 java interface functional-interface

假设我有一个界面:

public interface Function {
    double function (double input);
}
Run Code Online (Sandbox Code Playgroud)

现在,假设我在我的主类中的某个地方创建了这个接口的实例,

Function f = (x) -> x;
Run Code Online (Sandbox Code Playgroud)

如何以纯文本格式打印此功能?所以,有点像这样:

int f (double x) {return x}
Run Code Online (Sandbox Code Playgroud)

.toString在这上面运行Function打印就像Main$1@6d06d69c.我怎样才能获得此接口的java表示?

Cod*_*ice 2

请记住,函数的文本(也称为“代码”)仅在您编写它时才存在。您将其编译为字节码,然后在 Java 虚拟机上运行。在运行时,您编写的原始代码不再存在并且无法轻松检索。