如何使用方法引用在静态上下文中引用非静态方法? [重复]

问题描述 投票:0回答:0

基本上我在学习方法参考,我发现静态方法可以用这种格式引用:

<Class Name>::<function Name>

但我也发现我可以在静态上下文中引用 String 类的 length() 方法,但 length() 方法是一个非静态方法。 Here I am referring non-static method in static context but it gives no error and compiles fine

See, length() method is a non-static method

**见第一张图片,我的接口 {FrequentFunctions} 中的方法有一个 length 方法,它接受一个 String 参数,但 string 类的 length 方法不接受参数。那么我怎么可能引用一个与我正在为其实现的方法(FrequentFunctions 接口的长度(String str)方法)具有不同签名的方法

See here I cannot refer non-static method from static reference. So, how it is possible in case of String class length() method

See if the method I am referring has different signature then it gives error

java static-methods method-reference functional-interface
© www.soinside.com 2019 - 2024. All rights reserved.