一元運算符,也叫單項算符,一目運算符,一元算符 ,英文名字:UnaryOperator。
描述:接受一個參數(shù)為類型T,返回值類型也為T。
源碼:
1
2
3
4
5
6
7
8
9
10
11
|
public interface UnaryOperator<T> extends Function<T, T> { <span style= "color: #3366ff" > /** * Returns a unary operator that always returns its input argument. * * @param <T> the type of the input and output of the operator * @return a unary operator that always returns its input argument */ </span> static <T> UnaryOperator<T> identity() { return t -> t; } } |
測試代碼:
1
2
3
4
5
6
|
@Test public void test(){ super .print(UnaryOperator.identity().apply( 1 )); //<span style="color: #00ff00">輸出1 </span> super .print(UnaryOperator.identity().apply( false )); //<span style="color: #00ff00">輸出false </span> super .print(UnaryOperator.identity().apply( "string" )); //<span style="color: #00ff00">輸出string </span> } |
總結(jié)
以上就是本文關(guān)于Java編程一元運算符的實例介紹,希望對大家有所幫助。感謝大家對本站的支持。
原文鏈接:http://blog.csdn.net/z345434645/article/details/53876578