Soumettre la recherche
Mettre en ligne
Use Lambdas in Android
•
14 j'aime
•
1,907 vues
koji lin
Suivre
Use Lambda in Android
Lire moins
Lire la suite
Logiciels
Signaler
Partager
Signaler
Partager
1 sur 35
Télécharger maintenant
Télécharger pour lire hors ligne
Recommandé
Java8 lambda
Java8 lambda
koji lin
Java 開發者的函數式程式設計
Java 開發者的函數式程式設計
Justin Lin
lambda/closure – JavaScript、Python、Scala 到 Java SE 7
lambda/closure – JavaScript、Python、Scala 到 Java SE 7
Justin Lin
Hi Haskell
Hi Haskell
Jifeng Deng
Introduction to Basic Haskell Components (In Chinese)
Introduction to Basic Haskell Components (In Chinese)
ChengHui Weng
JavaScript 快速複習 2017Q1
JavaScript 快速複習 2017Q1
Sheng-Han Su
Scala+RDD
Scala+RDD
Yuanhang Wang
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
Justin Lin
Contenu connexe
Tendances
C python 原始碼解析 投影片
C python 原始碼解析 投影片
kao kuo-tung
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7
Justin Lin
twMVC#27 | C# 7.0 新功能介紹
twMVC#27 | C# 7.0 新功能介紹
twMVC
ES5 introduction
ES5 introduction
otakustay
Ecma script edition5-小试
Ecma script edition5-小试
lydiafly
Jscex:案例、阻碍、体会、展望
Jscex:案例、阻碍、体会、展望
jeffz
Javascript share
Javascript share
Xu Mac
Jscex:案例、经验、阻碍、展望
Jscex:案例、经验、阻碍、展望
jeffz
The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)
jeffz
Python速成指南
Python速成指南
March Liu
Wind.js无障碍调试与排错
Wind.js无障碍调试与排错
jeffz
Js is js(程劭非) (1)
Js is js(程劭非) (1)
looneyren
Python learn guide
Python learn guide
robin yang
Scala
Scala
popeast
Python變數與資料運算
Python變數與資料運算
吳錫修 (ShyiShiou Wu)
Intro to C++ Basic
Intro to C++ Basic
Shih Chi Lin
Sigreturn Oriented Programming
Sigreturn Oriented Programming
Angel Boy
Execution
Execution
Angel Boy
Net Parallel Programming .NET平行處理與執行序
Net Parallel Programming .NET平行處理與執行序
HO-HSUN LIN
程式人雜誌 -- 2014 年5月號
程式人雜誌 -- 2014 年5月號
鍾誠 陳鍾誠
Tendances
(20)
C python 原始碼解析 投影片
C python 原始碼解析 投影片
千呼萬喚始出來的 Java SE 7
千呼萬喚始出來的 Java SE 7
twMVC#27 | C# 7.0 新功能介紹
twMVC#27 | C# 7.0 新功能介紹
ES5 introduction
ES5 introduction
Ecma script edition5-小试
Ecma script edition5-小试
Jscex:案例、阻碍、体会、展望
Jscex:案例、阻碍、体会、展望
Javascript share
Javascript share
Jscex:案例、经验、阻碍、展望
Jscex:案例、经验、阻碍、展望
The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)
Python速成指南
Python速成指南
Wind.js无障碍调试与排错
Wind.js无障碍调试与排错
Js is js(程劭非) (1)
Js is js(程劭非) (1)
Python learn guide
Python learn guide
Scala
Scala
Python變數與資料運算
Python變數與資料運算
Intro to C++ Basic
Intro to C++ Basic
Sigreturn Oriented Programming
Sigreturn Oriented Programming
Execution
Execution
Net Parallel Programming .NET平行處理與執行序
Net Parallel Programming .NET平行處理與執行序
程式人雜誌 -- 2014 年5月號
程式人雜誌 -- 2014 年5月號
Similaire à Use Lambdas in Android
竞赛中C++语言拾遗
竞赛中C++语言拾遗
乐群 陈
Ooredis
Ooredis
iammutex
Ooredis
Ooredis
iammutex
張逸 - 研究所 / 轉學考計算機概論 、公職計算機概要 - 程式語言 - 試閱版
張逸 - 研究所 / 轉學考計算機概論 、公職計算機概要 - 程式語言 - 試閱版
逸 張
functional-scala
functional-scala
wang hongjiang
基于Eclipse和hadoop平台应用开发入门手册
基于Eclipse和hadoop平台应用开发入门手册
Zhen Li
论 Python 与设计模式。
论 Python 与设计模式。
勇浩 赖
VC++ Programming Training Lecture in Control Lab 301 of YSU
VC++ Programming Training Lecture in Control Lab 301 of YSU
Gavin Gao
Java SE 7 技術手冊 - 課後練習解答
Java SE 7 技術手冊 - 課後練習解答
Justin Lin
xwz 2010-10-31
xwz 2010-10-31
carlxwz
Reactive X 响应式编程
Reactive X 响应式编程
Jun Liu
Similaire à Use Lambdas in Android
(11)
竞赛中C++语言拾遗
竞赛中C++语言拾遗
Ooredis
Ooredis
Ooredis
Ooredis
張逸 - 研究所 / 轉學考計算機概論 、公職計算機概要 - 程式語言 - 試閱版
張逸 - 研究所 / 轉學考計算機概論 、公職計算機概要 - 程式語言 - 試閱版
functional-scala
functional-scala
基于Eclipse和hadoop平台应用开发入门手册
基于Eclipse和hadoop平台应用开发入门手册
论 Python 与设计模式。
论 Python 与设计模式。
VC++ Programming Training Lecture in Control Lab 301 of YSU
VC++ Programming Training Lecture in Control Lab 301 of YSU
Java SE 7 技術手冊 - 課後練習解答
Java SE 7 技術手冊 - 課後練習解答
xwz 2010-10-31
xwz 2010-10-31
Reactive X 响应式编程
Reactive X 响应式编程
Plus de koji lin
サーバーサイドでの非同期処理で色々やったよ
サーバーサイドでの非同期処理で色々やったよ
koji lin
G1GC
G1GC
koji lin
Using armeria to write your RPC
Using armeria to write your RPC
koji lin
使用 Java 上的 future/promise API
使用 Java 上的 future/promise API
koji lin
Annotation processing and code gen
Annotation processing and code gen
koji lin
Jcconf
Jcconf
koji lin
docker intro
docker intro
koji lin
Java8 time
Java8 time
koji lin
Java8 stream
Java8 stream
koji lin
Idea13
Idea13
koji lin
CompletableFuture
CompletableFuture
koji lin
Raspberry Pi with Java
Raspberry Pi with Java
koji lin
Services you can use to monitor and analyze mobile app
Services you can use to monitor and analyze mobile app
koji lin
Programming with Threads in Java
Programming with Threads in Java
koji lin
JQuery
JQuery
koji lin
山頂洞人日記 - 回歸到最純樸的開發
山頂洞人日記 - 回歸到最純樸的開發
koji lin
Android Location-based應用開發分享
Android Location-based應用開發分享
koji lin
Plus de koji lin
(17)
サーバーサイドでの非同期処理で色々やったよ
サーバーサイドでの非同期処理で色々やったよ
G1GC
G1GC
Using armeria to write your RPC
Using armeria to write your RPC
使用 Java 上的 future/promise API
使用 Java 上的 future/promise API
Annotation processing and code gen
Annotation processing and code gen
Jcconf
Jcconf
docker intro
docker intro
Java8 time
Java8 time
Java8 stream
Java8 stream
Idea13
Idea13
CompletableFuture
CompletableFuture
Raspberry Pi with Java
Raspberry Pi with Java
Services you can use to monitor and analyze mobile app
Services you can use to monitor and analyze mobile app
Programming with Threads in Java
Programming with Threads in Java
JQuery
JQuery
山頂洞人日記 - 回歸到最純樸的開發
山頂洞人日記 - 回歸到最純樸的開發
Android Location-based應用開發分享
Android Location-based應用開發分享
Use Lambdas in Android
1.
Retrolambda Use Lambdas in
Android kojilin@Cubie Inc. 2015/1/28
2.
Lambda?
3.
input.setOnClickListener(new View.OnClickListener() { @Override public
void onClick(View v) { } });
4.
input.setOnClickListener(v -> { ... });
5.
Lambda Syntax (int x,
int y) -> x + y
6.
(int x, int
y) -> x + y Argument List
7.
(int x, int
y) -> x + y Arrow Token
8.
(int x, int
y) -> x + y Body
9.
(int x, int
y) -> x + y () -> 42 (String s) -> { System.out.println(s); } ● Body is expression ● Body is statement block
10.
input.setOnClickListener(new View.OnClickListener() { @Override public
void onClick(View v) { } });
11.
input.setOnClickListener(v -> { ... });
12.
input.setOnClickListener(v -> ...);
13.
為何開心? • 各種用到 anonymous
class 的狀況 • Event listener • Runnable • RxJava • Future / Promise Pattern API
14.
input.setOnClickListener(new View.OnClickListener() { @Override public
void onClick(View v) { } });
15.
input.setOnClickListener(v -> { ... });
16.
handler.post(new Runnable() { @Override public
void run() { ... } });
17.
handler.post(() -> { ... });
18.
Observable.from(new Integer[] {...}) .filter(new
Func1<Integer, Boolean>() { @Override public Boolean call(Integer v) { return v < 4; } }).subscribe(new Action1<Integer>() { @Override public void call(Integer value) { System.out.println("Value: " + value); } });
19.
Observable.from(new Integer[] {...}) .filter(v
-> v < 4) .subscribe(value -> { System.out.println("Value: " + value); });
20.
設定只要幾個步驟
21.
下載 JDK 8
22.
build.gradle buildscript { ... dependencies { classpath
'me.tatarka:gradle-retrolambda:2.5.0' } } ... apply plugin: 'me.tatarka.retrolambda' ...
23.
設定原始碼支援 Java 8 語法
24.
• ProGuard • -dontwarn
java.lang.invoke.** • 而且 IDE Debug feature 也沒問題
25.
好像很不錯, 馬上導入 !?
26.
好像很不錯, 馬上導入 !? 等一下!!!
27.
怎麼做到的?
28.
Java source (.java) Java bytecode (.class) Dalvik
bytecode (.dex)
29.
Java source (.java) Java bytecode (.class) Dalvik
bytecode (.dex) Java 8 bytecode Java 5/6/7 bytecode
30.
• 未來 JDK
編譯出的 bytecode 改變 • 需等 retrolambda 支援 • 不支援的話,就得持續使用舊版 JDK • Android 新的編譯過程不經過 bytecode • Jack & Jill • 新增修改程式碼有時會有 NoClassDefFoundError • 未來 Android 上的 Java 語法應該(!?)會有 Java 8,所 以程式碼切換過去也不用改變
31.
另外...
32.
List<Integer> list =
Arrays.asList(1,2,3); Integer sum = list.stream() .map(i -> i * 2) .reduce(0, (x, y) -> x + y);
33.
List<Integer> list =
Arrays.asList(1,2,3); Integer sum = list.stream() .map(i -> i * 2) .reduce(0, (x, y) -> x + y); 等一下!!!
34.
• 因為是支援 lambda
語法,所以 java 8 的 API 並 沒有支援 • 可以使用 Guava, FunctionalJava 類的專案 Integer sum = fj.data.List.list(1,2,3) .map(i -> i * 2) .foldLeft(i -> (j -> i + j), 0);
35.
除了 lambda 外其他好處 •
Method reference • Effective Final • Generalized Target-Type Inference input.setOnClickListener(System.out::println);
Télécharger maintenant