??Android????????Java8
???????????? ???????[ 2017/1/18 11:41:27 ] ????????Android??? Java
???????
??????????????????????Java8???Щ?????????????
????Java8???????1??(Lambda????)
????Java8???????2??(?????????)
????Java8???????3??(Stream API)
??????????Android???????Java8?????????????Android????????Lambda??????Stream API??Java8?е?????????????Retrolambda??Lightweight-Stream-API??????????????????????Google?????????Android?????Java8???????????б????????????????Android????????????Java8??
?????????????Android???????Java8???????????????????????????Android N??????汾??????(??minSdkVersion>=24)????????????????????
????Lambda????(Lambda Expressions)?????????minSdkVersion<24???????????
????????????(Method References)?????????minSdkVersion<24???????????
????Stream API(Streams)
?????????????(Default Methods)
??????????(Repeating Annotations)
???????????????????????????Stream API?????????????????????????minSdkVersion>=24????Lambda????????????????minSdkVersion???????????Щ???????ü???????????????????????
????Jack(Java Android Compiler Kit)
?????????Android????????Java8?????????????????Android Studio??????2.1??????汾?????????μ?Jack(Java Android Compiler Kit)?????μ? Android ???????? Java ????????? Android ?????? Dalvik ???????????????????????? .jack ???????????????????????????????????????′????????????????? Dalvik ?????????????
????????????? Android Dalvik ???????????????????????????
??????? javac ????????
????javac (.java --> .class) --> dx (.class --> .dex)
?????°? Jack ????????
????Jack (.java --> .jack --> .dex)
????????
?????????????????Java8?????????????module?е?gradle.build????м??????′???
????<code class="Groovy">android {
????compileSdkVersion 24
????buildToolsVersion "24.0.3"
????defaultConfig {
????applicationId "me.baron.hellojava8"
????minSdkVersion 24
????targetSdkVersion 24
????versionCode 1
????versionName "1.0"
????jackOptions {
????enabled true
????}
????}
????compileOptions {
????sourceCompatibility JavaVersion.VERSION_1_8
????targetCompatibility JavaVersion.VERSION_1_8
????}
????}</code>
???????
???????????????ú????????Android????о??????????Java8????????????????????????button?????????????????д??
????<code class="java">button.setOnClickListener(new View.OnClickListener() {
????@Override
????public void onClick(View v) {
????v.setText("lalala");
????}
????});</code>
???????????????????Java8??Lambda????????????
????<code class="java">button.setOnClickListener(v -> v.setText("lalala"));</code>
??????????????minSdkVersion>=24??????????????Stream API??????????????????shapes???????????????????????????????μ?List?????Stream API??????????????
????<code class="java">List<shape> blue = shapes.stream()
????.filter(s -> s.getColor() == BLUE)
????.collect(Collectors.toList());</shape></code>
???????
????Java8???????????????????????????????????????????????????????Jack????????????????????????????μ?Jack????????????Instant Run??????????????????????????汾?????汾???????(?????Jack??Buck??Layoutcast??Freeline?????????????????????????????????????????????????????????)??????????Android????????????Java8?????????????????????Google????????????
?????ο??????
????https://developer.android.com/guide/platform/j8-jack.html
????https://medium.com/@sergii/java-8-in-android-n-preview-76184e2ab7ad
??????????????????е????£??????????????????GitHub?????鯇???
????????????https://zhuanlan.zhihu.com/baron
????GitHub??https://github.com/BaronZ88
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11