[問題] 一直看不懂官方API的一些表示方法[Java_General]

看板java作者 (Wei-Tse,Hsu)時間2年前 (2021/08/10 02:51), 2年前編輯推噓3(303)
留言6則, 4人參與, 2年前最新討論串1/1
不好意思一直有一個問題困擾我很久,目前也沒有找不到答案。 我在讀官方API的時候,有些符號一直看不懂,像是 t.ly/x64V 類別 Optional<T>裡面的方法flatMap ========================================== flatMap public <U> Optional<U> flatMapFunction<? super T, extends Optional<? extends U>> mapper) ========================================== 這一段要怎麼去識讀? <? 是甚麼意思 super T要是甚麼意思 extends是繼承嗎? 這方面有甚麼解釋文件可以閱讀嗎?一直搞不懂在哪裡有講解。 不知道哪邊有解釋,再麻煩大大解惑,感恩。 我之前都是拿看不懂的東西去google別人會解釋,但覺得這不是長久之道 所以想了解怎麼閱讀官方API的表示方法 Description: If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional. This method is similar to map(Function), but the mapping function is one whose result is already an Optional, and if invoked, flatMap does not wrap it within an additional Optional. Type Parameters: U - The type of value of the Optional returned by the mapping function Parameters: mapper - the mapping function to apply to a value, if present Returns: the result of applying an Optional-bearing mapping function to the value of this Optional, if a value is present, otherwise an empty Optional Throws: NullPointerException - if the mapping function is null or returns a null result -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.165.157.187 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/java/M.1628535118.A.FB7.html ※ 編輯: d0068267 (1.165.157.187 臺灣), 08/10/2021 03:12:45

08/10 03:21, 2年前 , 1F
關鍵字: java generic wildcard
08/10 03:21, 1F

08/10 03:22, 2年前 , 2F
這個是正式的 java 語法喔
08/10 03:22, 2F

08/10 14:49, 2年前 , 3F

08/10 18:29, 2年前 , 4F
https://tinyurl.com/3a7t5t6j 這個給你參考
08/10 18:29, 4F

08/10 19:28, 2年前 , 5F
你先找一套Java基礎語法過一下,認識一下多型,<
08/10 19:28, 5F

08/10 19:28, 2年前 , 6F
T>這個是泛型,很實用的
08/10 19:28, 6F
文章代碼(AID): #1X4NbE-t (java)