Hi Phil,
On 2/11/2013 2:21 PM, Phil Race wrote:
Joe,
|What were the criteria used to identify candidates?
It looks like its finding a public API interface with a
single abstract method.
To a first approximation, that is correct. I ran an annotation processor
over the sources in the jdk repo looking for interfaces which meet the
structural definition of a functional interface. The summary of that
definition is "defines one method," but there are complications in the
full definition that are accounted for in the checks I ran.
|My sense is that many of the ones identified are not ones
that would be appropriate for lambda expressions.
The pattern that would seem most useful is where the application
will need to iterate over a collection of these in parallel, is that
correct ?
Not necessary. The guidance I would given is that candidate interfaces
that are routinely instantiated today using anonymous classes should be
annotated with @FunctionalInterface. Note that a compiler will allow
one to use any type that meets the structural definition of a functional
interface in a lambda expression; adding the @FunctionalInterface
annotation just documents intent.
Some, like Printable, could not be properly used like that.
Maybe some of the listeners/observers might match the pattern
that there could be multiple of these that might need to be notified
but in reality there will usually be zero, sometimes one.
Perhaps the most likely candidate I see is ServiceRegistry.Filter|||.
|
BTW The decoder ring is here :- http://openjdk.java.net/groups/2d/
under "Regarding Java 2D's source code".
and there's a link there to additional info here :
http://openjdk.java.net/groups/2d/2dawtfiles.html
Thanks for the pointer,
-Joe
-phil.
On 2/8/2013 4:11 PM, Joseph Darcy wrote:
Hello,
As part of Project Lambda, a FunctionalInterface annotation type was
added to the platform to mark interfaces that are intended to be used
in lambda expressions. I've sent out a code review request to add
this annotation to types in the core-libs area [1] and have just
pushed the changeset into TL [2].
To assist the 2D team in adding analogous annotations to your types,
the list of candidate types in for 2D-related classes in java.* and
javax.* is given below. I recommend sub-tasks of JDK-8005297 "Add
FunctionalInterface support to the platform" be used to track the
work of adding @FunctionalInterface annotations to 2D types
In terms of how the annotation should be used, the benefit of the
annotation is that is clearly documents the type is intended to be
used for lambda expressions and is unlikely to evolve such that is
cannot be used with lambda expressions.
To a first approximation, if a candidate type today is commonly
created using anonymous inner classes, it is reasonable to add the
functionalInterface annotation. Note that the compiler will allow
any type meeting the structural requirements of a functional
interface to be
used in a lambda expression; the annotation just provides
documentation of intent.
Having misplaced my 2D vs AWT vs Swing decoder ring, consideration of
these 2D types was previously sent to other aliases [3] [4].
Thanks,
-Joe
[1]
http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-February/014292.html
[2] http://hg.openjdk.java.net/jdk8/tl/jdk/rev/522fb3867a3a
[3]
http://mail.openjdk.java.net/pipermail/awt-dev/2013-February/004213.html
[4]
http://mail.openjdk.java.net/pipermail/swing-dev/2013-February/002535.html
-=-=-=-=-
jdk/src/share/classes/java/awt/Stroke.java:58: Note: Candidate
functional interface
public interface Stroke {
^
jdk/src/share/classes/java/awt/image/TileObserver.java:39: Note:
Candidate functional interface
public interface TileObserver {
jdk/src/share/classes/java/awt/image/ImageObserver.java:40: Note:
Candidate functional interface
public interface ImageObserver {
^
jdk/src/share/classes/java/awt/image/renderable/RenderedImageFactory.java:47:
Note: Candidate functional interface
public interface RenderedImageFactory {
^
jdk/src/share/classes/java/awt/image/TileObserver.java:39: Note:
Candidate functional interface
public interface TileObserver {
jdk/src/share/classes/java/awt/print/Printable.java:105: Note:
Candidate functional interface
public interface Printable {
^
jdk/src/share/classes/java/awt/PrintGraphics.java:33: Note: Candidate
functional interface
public interface PrintGraphics {
^
jdk/src/share/classes/javax/print/FlavorException.java:39: Note:
Candidate functional interface
public interface FlavorException {
^
jdk/src/share/classes/javax/print/event/PrintServiceAttributeListener.java:37:
Note: Candidate functional interface
public interface PrintServiceAttributeListener {
^
jdk/src/share/classes/javax/print/event/PrintJobAttributeListener.java:34:
Note: Candidate functional interface
public interface PrintJobAttributeListener {
^
jdk/src/share/classes/javax/imageio/IIOParamController.java:99: Note:
Candidate functional interface
public interface IIOParamController {
^
jdk/src/share/classes/javax/imageio/event/IIOWriteWarningListener.java:46:
Note: Candidate functional interface
public interface IIOWriteWarningListener extends EventListener {
^
jdk/src/share/classes/javax/imageio/event/IIOReadWarningListener.java:46:
Note: Candidate functional interface
public interface IIOReadWarningListener extends EventListener {
^
jdk/src/share/classes/javax/imageio/metadata/IIOMetadataController.java:67:
Note: Candidate functional interface
public interface IIOMetadataController {
^
jdk/src/share/classes/javax/imageio/spi/ServiceRegistry.java:464:
Note: Candidate functional interface
public interface Filter {