Issue with compiler recognising a functional interface?
David Holmes
david.holmes at oracle.com
Thu Nov 8 02:58:11 PST 2012
On 8/11/2012 8:42 PM, Paul Sandoz wrote:
> Hi,
>
> I am running into an issue with the compiler with latest code.
Is this the bug Mike referred to here:
http://mail.openjdk.java.net/pipermail/lambda-dev/2012-November/006485.html
David
-----
> See end of email for all relevant interfaces.
>
> The compiler fails for:
>
> IntInfiniteIterator iterator = () -> t;
>
> [javac] /Users/sandoz/Projects/jdk8/lambda/jdk/src/share/classes/java/util/streams/primitives/Primitives.java:282: error: incompatible types: the target type must be a functional interface
> [javac] IntInfiniteIterator iterator = () -> t;
>
> But works for:
>
> InfiniteIterator<T> iterator = () -> t;
>
> I would of expected the former to work since there is just one non-default method.
>
> Paul.
>
> interface Iterator<E> {
> boolean hasNext();
>
> E next();
>
> default void remove() {
> throw new UnsupportedOperationException("remove");
> }
>
> default void forEach(Block<? super E> block) {
> while (hasNext())
> block.apply(next());
> }
> }
>
> interface InfiniteIterator<T> extends Iterator<T> {
> @Override
> public default boolean hasNext() {
> return true;
> }
> }
>
> interface IntIterator extends Iterator<Integer> {
>
> // Iterator<Integer>
>
> @Override
> default Integer next() {
> Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using boxed int", getClass().getName());
> return nextInt();
> }
>
>
> @Override
> default void forEach(Block<? super Integer> sink) {
> if (sink instanceof IntBlock) {
> forEach((IntBlock) sink);
> }
> else {
> Iterator.super.forEach(sink);
> }
> }
>
> //
>
> int nextInt();
>
> default void forEach(IntBlock sink) {
> while (hasNext()) {
> sink.applyInt(nextInt());
> }
> }
> }
>
> interface IntInfiniteIterator extends IntIterator {
> @Override
> default boolean hasNext() {
> return true;
> }
> }
>
>
More information about the lambda-dev
mailing list