lower bound wildcard type

Trust No. 1

I’m (still) wondering whether following two signatures have any practical (not technical) differences or not.

class Work {

    static <T> void work1(Class<T> type, T instance);

    static <T> void work1(Class<? super T> type, T instance);

Yes, it seems they are the same.

work1(String.class, "");
work2(String.class, "");

work1(CharSequence.class, "");
work2(CharSequence.class, "");

Work.<String>work1(String.class, "");
Work.<String>work2(String.class, "");

Work.<CharSequence>work1(CharSequence.class, "");
Work.<CharSequence>work2(CharSequence.class, "");

No, it seems they are not the same.

Work.<String>work1(CharSequence.class, ""); // won't compile
Work.<String>work2(CharSequence.class, "");

The truth is out there, agent Spender. Maybe you should find it for yourself.
– Fox William Mulder, Special Agent, FBI. –

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s