Express intersection A&B in Java

11 views
Skip to first unread message

zhong...@gmail.com

unread,
Sep 18, 2015, 3:28:52 PM9/18/15
to java.lang.fans
http://stackoverflow.com/q/32657561/2158288

If a method needs to accept an A&B argument, java has a very nice solution

    <T extends A&B> void f(T arg)

However, in other places where we need to express A&B, we might need a wrapper type. The OP asked for

    Class<? extends A&B>    ( & not allowed in wildcard bound (but why?) )

and I think I got a pretty nice solution with a wrapper type.

    Klass<? extends A, B>    

Zhong Yu
bayou.io

y s

unread,
Sep 18, 2015, 4:15:04 PM9/18/15
to zhong...@gmail.com, java.lang.fans
Wouldn't you be able to do something like:

    <T extends A&B> Class<T> ... ?

--
You received this message because you are subscribed to the Google Groups "java.lang.fans" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-lang-fan...@googlegroups.com.
To post to this group, send email to java-la...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/java-lang-fans/b1d85883-46a6-4e32-8512-303096193ee7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

zhong...@gmail.com

unread,
Sep 18, 2015, 4:32:47 PM9/18/15
to java.lang.fans
On Friday, September 18, 2015 at 3:15:04 PM UTC-5, Yuval Shavit wrote:
Wouldn't you be able to do something like:

    <T extends A&B> Class<T> ... ?



I guess not in OP's case. He probably wants an instance variable in a non-generic class.

It is common that we use types like `Class<? exends Foo>`; then sometimes we may as well need `Class<? extends Foo&Bar>` ... but we can't express that directly.

Zhong Yu
bayou.io
Reply all
Reply to author
Forward
0 new messages