kotlin 有的大家都想要,這點 Java 也一樣 (被逼的)
kotlin 吸收前人的經驗,只留下實用的功能,現在變成現代化語言的標竿了。Dart 也許到了 4.0 功能上也會差不多
改得超多的,之前的什麼 any T 都不見了
In Valhalla, we convert from inline to reference types via an inline widening conversion. This is similar to boxing, but it has a significant difference: the result of the conversion is not an identity object (as a box would be), but a reference to an inline object.
Boxing
的話是直接開一個肥 Object, Reference projection
的話只是一個 reference 指向 inline object,所以整個輕量化。
看到後面,最大缺點是 Optional
要寫成
Optional.inline<User> userOpt = Optional.of( findUserById(12))
這種奇怪的型式才能得到最佳化,然後像是 Map API 也變難懂:
public V.ref get(K key);
看到 return V.ref
一定很傻眼
singleton is evil !
一開始都是立意良好, 但隨著程式維護就漸漸爛了, 也不是只有 flutter 有這個問題.
不過 GUI 的程式會很想用 singleton 就是了, 因為 UI 的程式通常會很深 (react 這種 comp tree 的更嚴重), 不用 singleton 很麻煩...
這個問題要解決就是養成寫 test 的習慣, 一旦要 test 就會發現導入 singleton 很難測
當然也是會發生維護的人發現 test 過不了, 然後全砍掉, 改回用 singleton, 這就不是什麼 practice 能救的問題了