Converting between structurally compatible function types

Millies, Sebastian Sebastian.Millies at softwareag.com
Mon Feb 23 17:36:27 UTC 2015


sorry for the noise, figured out how to use the identity function for this:

Function<Integer,Object> id = n -> n
g = id.compose(f);

-- Sebastian

-----Original Message-----
From: lambda-dev [mailto:lambda-dev-bounces at openjdk.java.net] On Behalf Of Millies, Sebastian
Sent: Monday, February 23, 2015 6:32 PM
To: lambda-dev at openjdk.java.net
Subject: Converting between structurally compatible function types

Hello there,

I have a very basic question: why does the following not compile:

Function<String,Integer> f = s -> 1;
Function<String,Object> g = f;

After all, I would expect that anywhere where a function from String to arbitrary objects is required, I can supply a function to integers in particular.
I guess Java just sees the names are different, and that’s it?

How do I best convert between the two types?


n  Sebastian


Software AG – Sitz/Registered office: Uhlandstraße 12, 64297 Darmstadt, Germany – Registergericht/Commercial register: Darmstadt HRB 1562 - Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman), Eric Duffaut, Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com




More information about the lambda-dev mailing list