Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #38891
| Path | csiph.com!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd3-ae38-0-ada1-1290-a847-1871.ipv6dyn.netcologne.de!not-for-mail |
|---|---|
| From | Patrick Roemer <sangamon@netcologne.de> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Store Suppliers in a map |
| Date | Wed, 10 Apr 2019 16:12:50 +0200 |
| Organization | news.netcologne.de |
| Distribution | world |
| Message-ID | <q8ktl2$g7$1@newsreader4.netcologne.de> (permalink) |
| References | <88a3b286-0d96-425e-ac82-c02e3ebcc84a@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 10 Apr 2019 14:12:50 -0000 (UTC) |
| Injection-Info | newsreader4.netcologne.de; posting-host="2001-4dd3-ae38-0-ada1-1290-a847-1871.ipv6dyn.netcologne.de:2001:4dd3:ae38:0:ada1:1290:a847:1871"; logging-data="519"; mail-complaints-to="abuse@netcologne.de" |
| User-Agent | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.24) Gecko/20100411 Thunderbird/2.0.0.24 Mnenhy/0.7.6.0 |
| In-Reply-To | <88a3b286-0d96-425e-ac82-c02e3ebcc84a@googlegroups.com> |
| Content-Language | en-US |
| Xref | csiph.com comp.lang.java.programmer:38891 |
Show key headers only | View raw
Responding to mike: > I need to to different suppliers: > > - Supplier<String> > - Supplier<Integer> > - Supplier<List<String>> > > Map<String, Supplier> map= new HashMap<>(); > > How can I define a map ( some similar collection ) to store these different suppliers in? > > When I get it from map what will be the type? You need a uniform key type. That leaves only raw Supplier or wildcard Supplier<?> or similar, just as you put it above. Thus the compile-time key type you receive from the map will be raw Supplier or wildcard Supplier<?>, as well. Just assuming that through some magic you'd be able to actually yank a compile-time Supplier<String> from the map - how would you proceed working with it? The client code that queries the map would probably be generic in the Supplier's result type, anyway, so you wouldn't have gained much. You could try to use an HList[1] or some abstraction on top of it. I haven't used those in Java, yet. From my limited experience in Scala I'd say this isn't for the faint of heart, and I wouldn't expect it to be more friendly in Java - see [2]. :) Or you could bury the whole remaining computation, starting from the Supplier, in a custom data type and use this as a key type. "Inside" this type, the proper type would be known then, generically or statically. There may be other, less cumbersome approaches, depending on what you actually want to achieve. Best regards, Patrick [1] http://www.functionaljava.org/javadoc/4.8.1/functionaljava/fj/data/hlist/HList.html [2] http://www.functionaljava.org/examples-java7.html#hlistAppend
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Store Suppliers in a map mike <mikaelpetterson@hotmail.com> - 2019-04-09 22:01 -0700
Re: Store Suppliers in a map mike <mikaelpetterson@hotmail.com> - 2019-04-09 22:04 -0700
Re: Store Suppliers in a map Patrick Roemer <sangamon@netcologne.de> - 2019-04-10 16:12 +0200
Re: Store Suppliers in a map Patrick Roemer <sangamon@netcologne.de> - 2019-04-10 16:35 +0200
Re: Store Suppliers in a map Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-04-10 19:07 +0200
csiph-web