一元运算符,也叫单项算符,一目运算符,一元算符 ,英文名字:unaryoperator。
描述:接受一个参数为类型t,返回值类型也为t。
源码:
public interface unaryoperator extends function {
/**
* returns a unary operator that always returns its input argument.
*
* @param the type of the input and output of the operator
* @return a unary operator that always returns its input argument
*/
static unaryoperator identity() {
return t -> t;
}
}
测试代码:
@test
public void test(){
super.print(unaryoperator.identity().apply(1));//输出1
super.print(unaryoperator.identity().apply(false));//输出false
super.print(unaryoperator.identity().apply("string"));//输出string
}
总结
以上就是本文关于java编程一元运算符的实例介绍,希望对大家有所帮助。感谢大家对本站的支持。
希望与广大网友互动??
点此进行留言吧!
本文发布于:2024-02-02 10:54:51,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170684249043325.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |