scala函数名的实现。Java(scala编程)中存在(u.isUpper)
// scala code
val nameHasUpperCase = name.exists(_.isUpperCase)
In principle, such control abstractions are possible in Java as well. You’d need to define an interface that contains a method with the abstracted functionality. For instance, if you wanted to support querying over strings, you might invent an interface, named CharacterProperty, which has just one method, hasProperty: // this is Java
interface CharacterProperty { boolean hasProperty(char ch); }
With that interface you could formulate a method exists in Java: It takes a string and CharacterProperty and returns true if there’s a character in the string that satisfies the property. You could then invoke exists as follows:
//this is Java
exists(name, new CharacterProperty() {
public boolean hasProperty(char ch) {
return Character.isUpperCase(ch); }
});
这个案子我办不下去。如何解释作者的话,并用Java语言和接口实现这一点?任何帮助都将不胜感激,谢谢
共 (0) 个答案