摘要:摘要添加了表達式閉包和特性支持,包括方法的引用,增強類型推斷,和虛擬擴展方法。圍繞的語言功能支持包括虛擬擴展方法,這將使接口的源代碼和二進制兼容的方式演變升級。
Author:Joseph D. Darcy
Organization:Oracle
Owner:Brian Goetz
Created:2011/11/1
Updated:2013/2/21
Type:Feature
State:Funded
Component:–/–
Scope:SE
JSR:269 MR, 335
Discussion:lambda dash dev at openjdk dot java dot net
Start:2011/Q4
Blocks:107, 109
Effort:XL
Duration:XL
Reviewed-by:Brian Goetz
Endorsed-by:Brian Goetz
Funded-by:Oracle
Release 8
Target M7
Summary
Add lambda expressions (closures) and supporting features, including method references, enhanced type inference, and virtual extension methods, to the Java programming language and platform.
摘要
Java 8添加了Lambda表達式(閉包)和特性支持,包括方法的引用,增強類型推斷,和虛擬擴展方法。
Goals
The primary features of lambda expressions and virtual extension methods, along with their set of secondary supporting features, further several platform goals:
Simplifying the creation and consumption of more abstract, higher-performance libraries
Supporting smoother library evolution with migration compatibility
Besides adding a now-common feature to the Java programming language, lambda expressions open up possibilities for improved multicore support by enabling internal iteration idioms.
The supporting language features around lambda include virtual extension methods, which will allow interfaces to be evolved in a source and binary compatible fashion.
In addition to language changes, coordinated libraries and JVM changes will occur as well.
Note that the active and ongoing Project Lambda OpenJDK project pre-dates the JEP process, as does the corresponding JSR, JSR 335, which is targeted for Java SE 8 (JSR 336).
Lambda表達式和虛擬擴展方法的主要特點,以及對于Java語言的一整套輔助支持特性,起到促進一些平臺的目的:
·使得更加抽象,性能更高的庫創建和消費起來更簡單 ·支持平滑的演進庫與兼容性遷移
Lamdba除了增加一個現有常用的特點外,還開創的通過使內部迭代語句支持了多核的特性。
圍繞lambda的語言功能支持包括虛擬擴展方法,這將使接口的源代碼和二進制兼容的方式演變升級。
除了語言的變化之外,協調庫和JVM的變化也會變得更加友好。
需要注意的是,積極和持續的Project Lambda OpenJDK項目的預期,JEP的過程,與相應的JSR,JSR335一樣,只是針對用于Java SE8(JSR336)。
Non-Goals
The language features of function types and general control abstraction are not goals of adding lambda expressions to Java. However, the intention is to not preclude the addition of such features in the future.
函數類型和通常的控制抽象等語言特點并不是添加lambda表達式到Java的目標,然而,意圖是不排除在將來添加這些特征。
Motivation
Many other commonly used object-oriented programming languages, including those hosted on the JVM (for example Groovy, Ruby, and Scala) and hosted on other virtual machines (C# on the CLR), include support for closures. Therefore, Java programmers are increasingly familiar with the language feature and the programming models it enables.
Of particular interest is enabling the idiom of internal iteration. Arrays and collections currently support external iteration, where the control logic of an iteration lives outside of the data structure being traversed. For example, a for-each loop over an array or a collection is an example of external iteration. The semantics of the for loop in Java mandates strict serial iteration, which means that the only means the programmer has of iterating over a standard collection will not allow the use of all the available cores.
With internal iteration, the data structure is passed a piece of code to execute, as a lambda expression, and the data structure is responsible for partitioning the computation and reporting the results. Since the data structure is familiar with its own internal details it can potentially choose a better scheduling of the computation by tuning options such as
Alternate execution order
Concurrent execution using thread pools
Parallel execution using partitioning and work stealing. The fork/join framework, added in Java SE 7, is one such candidate parallel execution framework and offers performance-robust partitioning of work over a wide range of core counts.
許多其他常用的面向對象的編程語言,包括那些托管在JVM(例如Groovy,Ruby,和Scala),以及托管在其他虛擬機(C#在CLR),都包含閉包功能。因此,Java程序員也越來越熟悉的閉包的語言功能以及它的編程模型。
特別令人感冒的是內部迭代語句的特性,數組和集合目前支持外部迭代,就是控制迭代的邏輯代碼在數據結構外部,從而實現數據的迭代。例如,for-each迭代數組和集合就是這樣一個外部迭代的例子。Java中for-each迭代就是比較嚴格的串行迭代,這意味著,在不允許使用所有可用的核心庫的情況下。程序員只能用一種方法來實現遍歷一個標準的集合。
使用內部迭代,數據結構就像lamdba表達式一樣執行代碼片段,并且數據結構也負責分割計算并返回結果。因為數據結構和他自己的內部細節想似。他可以通過調整選項,然后選擇最好的任務調度進行程序計算。就像:
修改執行順序
使用線程池同步執行
使用分區和工作竊取并行執行,The fork/join framework,在JavaSE 7中添加,是一個這樣的候選并行處理框架,工作性能可靠的分區多核心計數。
A prototypical example of the internal iteration style is a sequence of filter-map-reduce operations such as:
int maxFooWeight =
collection.filter( /* isFoo Predicate as a lambda /)
.map( / Map a Foo to its weight with a lambda /)
.max(); / Reduction step */
The lambda expressions are expressions with concise(簡明的) syntax(語法) to represent the desired operation. This style is in lieu(代替) of one or moreexplicit(明確的) for loops(環) which would unnecessary constrain(驅使) the iteration order over the collection. In addition, a well-designed algorithm(算法) can not onlyexecute(實行) these sets of operations in parallel, but can also aggregate(集合) the three operations into a single parallel pass.
Project Lambda also includes virtual(虛擬的) extension(延長) methods, which will address the long-standing limitation(限制) of not being able to add methods to widely-usedinterfaces(界面) because of source compatibility(兼容性) concerns(關系).
By adding extension methods to the existing collection interfaces, such asjava.util.Collection and java.util.List, existing implementations(實現) of those types can participate(參與) in the new programming idiom. Implementations of those types in the JDK (and elsewhere(在別處)) can override(推翻) the default implementations of the extension methods from the superinterfaces to provide higher-performance or otherwisespecialized(專業的) implementations.
Description
The in-progress OpenJDK project page for Project Lambda and corresponding JSRhave the most up-to-date(最新的) information about the details of the effort.
The platform components(成分) impacted(影響) by the overall Project Lambda effort include:
The specification(規格) of the Java programming language
The specification of the Java virtual(虛擬的) machine
The reference(參考) implementation(實現) of the language changes in javac
Class file changes to support compilation(編輯) of lambda expressions and virtual extension(延長) methods
(Possible) JVM enhancements(增加) to improve execution(執行) of lambdas
JVM changes to support virtual extension methods
Core API changes to add virtual extension methods
Core API changes to support use of lambda expressions
Updates to the JDK libraries to use the new extension methods
Updates to the reflective(反射的) APIs, such as core reflection(反射)andjavax.lang.model, to expose lambda and extension method related information
Updates to class file tools like javap and pack200/unpack200 to understand new JVM attributes(屬性)
(Possible) serialization(序列化) updates, including IIOP serialization
Enhancements(增加) to javadoc to indicate(表明) which interfaces(界面) can be used for lambdas
Language runtime in java.lang.* to support the translation of lambda expressions and virtual(虛擬的) extension(延長) methods
Alternatives
Project Lambda started with a straw-man proposal and has gone through several “State of the Lambda” iterations which have evolved(發展) both the syntax(語法) andfeature(特色) set of the project.
The work on lambda expression portion(部分) of Project Lambda is informed(通知) bynumerous(許多的) previous efforts, including but not limited to:
BGGA,
CICE
FCM
Pizza
The feature(特色) set of Project Lambda is judged to better address the needs ofevolving(發展) the Java platform than the earlier proposals(提議).
The design of virtual extension methods is likewise(同樣地) informed(通知) by a large body of prior(優先的) work in the programming language community including:
multiple inheritance(繼承) in C++
static extension(延長) methods in C#
traits in Fortress
traits in Scala
mixins in Strongtalk
Compared to other language environments, the Java language has always had much more predictable semantics(語義學), built-in(嵌入的) primitive(原始的) types are of a known size, exceptions(例外) are thrown at precise(精確的) locations, the order ofexecution(執行) of expressions is precisely defined(定義), and so on. Loosening(放松) the semantics of the built-in for and while loops(環) to allow auto-parallelization attempts was judged to be neither desirable(令人滿意的) nor sufficient(足夠的) to meet the goals of supporting multi-core.
Testing
In addition to unit/regression(回歸) tests, as a new language feature(特色) JCK tests will also be developed.
The utility(實用) of the feature will also be validated(證實) through usage(使用) in the JDK platform libraries.
Risks and Assumptions
As a large effort touching many aspects(方面) of the platform, there is the possibility forunforeseen(未預見到的) complications(并發癥) and interactions(相互作用) to arise.
By starting early and planning for several iterations(迭代) of, say, the supporting libraries work, the impact(影響) of those complications should be mitigated(緩和).
Dependences
The currently preferred implementation(實現) approach(方法) for lambda expressionsrelies(依靠) oninvokedynamic and method handles introduced by JSR 292. Therefore,acceptable(可接受的) performance of lambda depends on acceptable performance of method handles, amongst(在…之中) other factors(因素).
There is expected to be feedback(反饋) between the libraries work (JEPs 107 and 109) and the language features.
Impact
Other JDK components(成分): The impact of other JDK components isoutlined(概述) in the description section.
Compatibility(兼容性): Virtual(虛擬的) extension(延長) methods are intended to allow source compatible(兼容的) evolution(演變) of interfaces(界面).add virtual extension methods
Security: Security review will be needed on aspect of the runtime implementation of lambdas.
Performance/scalability(可擴展性): Performance of lambda-friendly idiomsversus(對) traditional idioms should be tracked.
Documentation(文件材料): User guides and supporting documentation needs to be written.
TCK: As a large platform feature(特色), language and library TCKs need to be developed.
我的博客ENUE.CN
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/66141.html
摘要:跳票之王終于發布了帶來了一系列激動人心的新特性,包括新的時間日期,以及和,在多線程環境下性能提升不少。 跳票之王Java8終于發布了! Java8帶來了一系列激動人心的新特性,包括lambda、新的時間日期AOPI,以及AtomicInteger和AtomicLong,在多線程環境下性能提升不少。 showImg(http://segmentfault.com/img/bVb0D2...
摘要:大家好,上一篇小樂給大家講述了樂字節核心特性表達式,點擊回顧。接下來繼續核心特性之函數式接口。感謝大家欣賞小樂帶來的核心特性之函數式接口,接下來還會更多核心技術講解,請關注樂字節如需要視頻課程,請搜索樂字節騰訊課堂 大家好,上一篇小樂給大家講述了《樂字節-Java8核心特性-Lambda表達式》,點擊回顧。接下來繼續:Java8核心特性之函數式接口。 什么時候可以使用Lambda?通常...
摘要:很多語言等從設計之初就支持表達式。注意此時外部局部變量將自動變為作為方法返回值例子返回判斷字符串是否為空判斷字符串是否為空今天關于新特性表達式就講到這里了,接下來我會繼續講述新特性之函數式接口。 上一篇文章我們了解了Java8新特性-接口默認方法,接下來我們聊一聊Java8新特性之Lambda表達式。 Lambda表達式(也稱為閉包),它允許我們將函數當成參數傳遞給某個方法,或者把代碼...
摘要:一表達式匿名內部類最大的問題在于其冗余的語法,比如前面的中五行代碼僅有一行是在執行任務??偨Y基于詞法作用域的理念,表達式不可以掩蓋任何其所在上下文的局部變量。 轉載請注明出處:https://zhuanlan.zhihu.com/p/20540175 在介紹Lambda表達式之前,我們先來看只有單個方法的Interface(通常我們稱之為回調接口): public interface...
摘要:上下文比如接受它傳遞的方法的參數,或接受它的值的局部變量中表達式需要的類型稱為目標類型。但局部變量必須顯式聲明為,或事實上是。換句話說,表達式只能捕獲指派給它們的局部變量一次。注捕獲實例變量可以被看作捕獲最終局部變量。 簡介 概念 Lambda 表達式可以理解為簡潔地表示可傳遞的匿名函數的一種方式:它沒有名稱,但它有參數列表、函數主體、返回類型,可能還有一個可以拋出的異常列表。 匿名...
閱讀 882·2021-11-23 09:51
閱讀 1089·2021-11-15 17:57
閱讀 1667·2021-09-22 15:24
閱讀 812·2021-09-07 09:59
閱讀 2221·2019-08-29 15:10
閱讀 1849·2019-08-29 12:47
閱讀 751·2019-08-29 12:30
閱讀 3369·2019-08-26 13:51