Generic method reference type specifying before/after :: operator
Clash Royale CLAN TAG#URR8PPP
up vote
17
down vote
favorite
What is the difference between the following method references,
BiPredicate<List<String>,String> contains1 = List<String>::contains;
BiPredicate<List<String>,String> contains2 = List::<String>contains;
BiPredicate<List<String>,String> contains3 = List<String>::<String>contains;
Do the cases have special names? Is there any example similar to the usage?
java generics java-8 method-reference
 |Â
show 2 more comments
up vote
17
down vote
favorite
What is the difference between the following method references,
BiPredicate<List<String>,String> contains1 = List<String>::contains;
BiPredicate<List<String>,String> contains2 = List::<String>contains;
BiPredicate<List<String>,String> contains3 = List<String>::<String>contains;
Do the cases have special names? Is there any example similar to the usage?
java generics java-8 method-reference
7
Good question...
â ernest_k
Aug 10 at 12:35
Related: stackoverflow.com/questions/31245127/â¦. Seems the first syntax specifies type argument forList
, whereas the second specifies type argument forcontains
(unnecessary in this case because the method is not generic)
â ernest_k
Aug 10 at 12:44
3
And, of course,BiPredicate<List<String>,String> contains1 = List<String>::<String>contains;
.
â Andy Turner
Aug 10 at 12:45
2
As a related side-note, and a partial explanation: it's legal to supply type arguments to a non-generic method, such aslist.<Number>contains("foo")
. They're just ignored. (As for why the JLS authors chose to allow it, though, I don't know.)
â Radiodef
Aug 10 at 16:53
1
@snr Why is it legal to supply type arguments to a non-generic method? You can find the answer here.
â Oleksandr
Aug 10 at 20:03
 |Â
show 2 more comments
up vote
17
down vote
favorite
up vote
17
down vote
favorite
What is the difference between the following method references,
BiPredicate<List<String>,String> contains1 = List<String>::contains;
BiPredicate<List<String>,String> contains2 = List::<String>contains;
BiPredicate<List<String>,String> contains3 = List<String>::<String>contains;
Do the cases have special names? Is there any example similar to the usage?
java generics java-8 method-reference
What is the difference between the following method references,
BiPredicate<List<String>,String> contains1 = List<String>::contains;
BiPredicate<List<String>,String> contains2 = List::<String>contains;
BiPredicate<List<String>,String> contains3 = List<String>::<String>contains;
Do the cases have special names? Is there any example similar to the usage?
java generics java-8 method-reference
edited Aug 10 at 14:51
asked Aug 10 at 12:33
snr
1
1
7
Good question...
â ernest_k
Aug 10 at 12:35
Related: stackoverflow.com/questions/31245127/â¦. Seems the first syntax specifies type argument forList
, whereas the second specifies type argument forcontains
(unnecessary in this case because the method is not generic)
â ernest_k
Aug 10 at 12:44
3
And, of course,BiPredicate<List<String>,String> contains1 = List<String>::<String>contains;
.
â Andy Turner
Aug 10 at 12:45
2
As a related side-note, and a partial explanation: it's legal to supply type arguments to a non-generic method, such aslist.<Number>contains("foo")
. They're just ignored. (As for why the JLS authors chose to allow it, though, I don't know.)
â Radiodef
Aug 10 at 16:53
1
@snr Why is it legal to supply type arguments to a non-generic method? You can find the answer here.
â Oleksandr
Aug 10 at 20:03
 |Â
show 2 more comments
7
Good question...
â ernest_k
Aug 10 at 12:35
Related: stackoverflow.com/questions/31245127/â¦. Seems the first syntax specifies type argument forList
, whereas the second specifies type argument forcontains
(unnecessary in this case because the method is not generic)
â ernest_k
Aug 10 at 12:44
3
And, of course,BiPredicate<List<String>,String> contains1 = List<String>::<String>contains;
.
â Andy Turner
Aug 10 at 12:45
2
As a related side-note, and a partial explanation: it's legal to supply type arguments to a non-generic method, such aslist.<Number>contains("foo")
. They're just ignored. (As for why the JLS authors chose to allow it, though, I don't know.)
â Radiodef
Aug 10 at 16:53
1
@snr Why is it legal to supply type arguments to a non-generic method? You can find the answer here.
â Oleksandr
Aug 10 at 20:03
7
7
Good question...
â ernest_k
Aug 10 at 12:35
Good question...
â ernest_k
Aug 10 at 12:35
Related: stackoverflow.com/questions/31245127/â¦. Seems the first syntax specifies type argument for
List
, whereas the second specifies type argument for contains
(unnecessary in this case because the method is not generic)â ernest_k
Aug 10 at 12:44
Related: stackoverflow.com/questions/31245127/â¦. Seems the first syntax specifies type argument for
List
, whereas the second specifies type argument for contains
(unnecessary in this case because the method is not generic)â ernest_k
Aug 10 at 12:44
3
3
And, of course,
BiPredicate<List<String>,String> contains1 = List<String>::<String>contains;
.â Andy Turner
Aug 10 at 12:45
And, of course,
BiPredicate<List<String>,String> contains1 = List<String>::<String>contains;
.â Andy Turner
Aug 10 at 12:45
2
2
As a related side-note, and a partial explanation: it's legal to supply type arguments to a non-generic method, such as
list.<Number>contains("foo")
. They're just ignored. (As for why the JLS authors chose to allow it, though, I don't know.)â Radiodef
Aug 10 at 16:53
As a related side-note, and a partial explanation: it's legal to supply type arguments to a non-generic method, such as
list.<Number>contains("foo")
. They're just ignored. (As for why the JLS authors chose to allow it, though, I don't know.)â Radiodef
Aug 10 at 16:53
1
1
@snr Why is it legal to supply type arguments to a non-generic method? You can find the answer here.
â Oleksandr
Aug 10 at 20:03
@snr Why is it legal to supply type arguments to a non-generic method? You can find the answer here.
â Oleksandr
Aug 10 at 20:03
 |Â
show 2 more comments
3 Answers
3
active
oldest
votes
up vote
14
down vote
accepted
First of all, that is called a type witness (in the official Oracle Tutorial) or TypeArguments (in the JLS Sec 15.12) and you are effectively helping the compiler with such constructs.
One example:
private static void test(Callable<Object> call)
private static void test(Runnable run)
static class Gen<T>
And call it via test(Gen::new);
(this will fail, never mind why), but the point is that you add a type witness to help the compiler, so this would work
test(Gen<String>::new);
So when you write List<String>
, you have added a type witness for the target type - List
that is; in the second case you are adding one for the method contains
- but it's not generic, so it is ignored.
3
Where does the term "type witness" come from? I can't find it in the language spec.
â Andy Turner
Aug 10 at 12:50
3
@AndyTurner docs.oracle.com/javase/tutorial/java/generics/⦠search for "type witness", I was not saying it's in theJLS
(might be, not sure)
â Eugene
Aug 10 at 12:51
4
@Lino the official java tutorial calls it that way, I'll stick to that :)
â Eugene
Aug 10 at 12:56
2
The word "witness" doesn't appear in JLS (9, at least). They are simply calledTypeArguments
there.
â Andy Turner
Aug 10 at 12:58
1
@AndyTurnerTypeArguments
it is! thank you
â Eugene
Aug 10 at 13:00
add a comment |Â
up vote
5
down vote
In:
BiPredicate<List<String>, String> contains2 = List::<String>contains;
<String>
is a type argument to a non-generic List.contains
method1.
While in:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
<String>
is a type argument to a List
.
1 - In this particular case a type argument is ignored according to the JLS ç15.12.2.1:
A non-generic method may be potentially applicable to an invocation
that supplies explicit type arguments. In such a case, the type
arguments will simply be ignored.
Is there any difference btw type parameter and type argument terms in this context? If yes, what is this?
â snr
Aug 10 at 18:41
1
Yes, there is a difference.E
inList<E>
is a type parameter and theString
inList<String>
is a type argument. You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument -String
in this case - to theList
itself (source).
â Oleksandr
Aug 10 at 19:09
thank you indeed
â snr
Aug 10 at 22:10
add a comment |Â
up vote
4
down vote
Here's what Intellij tells me about them:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
Explicit type arguments can be inferred
BiPredicate<List<String>, String> contains2 = List::<String>contains;
Type arguments are redundant for the non-generic method reference
If you were to split these up into their respective lambda functions, I believe you'd see the following:
BiPredicate<List<String>, String> contains1 = (List<String> strings, String o) -> strings.contains(o);
BiPredicate<List<String>, String> contains2 = (strings, o) -> strings.<String>contains(o);
As we know, (List<String> strings, String o)
can be replaced by (strings, o)
and <String>
on the second line is unneeded (as String#contains
isn't generic), so it's safe to assume that both method references are equivalent.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
14
down vote
accepted
First of all, that is called a type witness (in the official Oracle Tutorial) or TypeArguments (in the JLS Sec 15.12) and you are effectively helping the compiler with such constructs.
One example:
private static void test(Callable<Object> call)
private static void test(Runnable run)
static class Gen<T>
And call it via test(Gen::new);
(this will fail, never mind why), but the point is that you add a type witness to help the compiler, so this would work
test(Gen<String>::new);
So when you write List<String>
, you have added a type witness for the target type - List
that is; in the second case you are adding one for the method contains
- but it's not generic, so it is ignored.
3
Where does the term "type witness" come from? I can't find it in the language spec.
â Andy Turner
Aug 10 at 12:50
3
@AndyTurner docs.oracle.com/javase/tutorial/java/generics/⦠search for "type witness", I was not saying it's in theJLS
(might be, not sure)
â Eugene
Aug 10 at 12:51
4
@Lino the official java tutorial calls it that way, I'll stick to that :)
â Eugene
Aug 10 at 12:56
2
The word "witness" doesn't appear in JLS (9, at least). They are simply calledTypeArguments
there.
â Andy Turner
Aug 10 at 12:58
1
@AndyTurnerTypeArguments
it is! thank you
â Eugene
Aug 10 at 13:00
add a comment |Â
up vote
14
down vote
accepted
First of all, that is called a type witness (in the official Oracle Tutorial) or TypeArguments (in the JLS Sec 15.12) and you are effectively helping the compiler with such constructs.
One example:
private static void test(Callable<Object> call)
private static void test(Runnable run)
static class Gen<T>
And call it via test(Gen::new);
(this will fail, never mind why), but the point is that you add a type witness to help the compiler, so this would work
test(Gen<String>::new);
So when you write List<String>
, you have added a type witness for the target type - List
that is; in the second case you are adding one for the method contains
- but it's not generic, so it is ignored.
3
Where does the term "type witness" come from? I can't find it in the language spec.
â Andy Turner
Aug 10 at 12:50
3
@AndyTurner docs.oracle.com/javase/tutorial/java/generics/⦠search for "type witness", I was not saying it's in theJLS
(might be, not sure)
â Eugene
Aug 10 at 12:51
4
@Lino the official java tutorial calls it that way, I'll stick to that :)
â Eugene
Aug 10 at 12:56
2
The word "witness" doesn't appear in JLS (9, at least). They are simply calledTypeArguments
there.
â Andy Turner
Aug 10 at 12:58
1
@AndyTurnerTypeArguments
it is! thank you
â Eugene
Aug 10 at 13:00
add a comment |Â
up vote
14
down vote
accepted
up vote
14
down vote
accepted
First of all, that is called a type witness (in the official Oracle Tutorial) or TypeArguments (in the JLS Sec 15.12) and you are effectively helping the compiler with such constructs.
One example:
private static void test(Callable<Object> call)
private static void test(Runnable run)
static class Gen<T>
And call it via test(Gen::new);
(this will fail, never mind why), but the point is that you add a type witness to help the compiler, so this would work
test(Gen<String>::new);
So when you write List<String>
, you have added a type witness for the target type - List
that is; in the second case you are adding one for the method contains
- but it's not generic, so it is ignored.
First of all, that is called a type witness (in the official Oracle Tutorial) or TypeArguments (in the JLS Sec 15.12) and you are effectively helping the compiler with such constructs.
One example:
private static void test(Callable<Object> call)
private static void test(Runnable run)
static class Gen<T>
And call it via test(Gen::new);
(this will fail, never mind why), but the point is that you add a type witness to help the compiler, so this would work
test(Gen<String>::new);
So when you write List<String>
, you have added a type witness for the target type - List
that is; in the second case you are adding one for the method contains
- but it's not generic, so it is ignored.
edited Aug 10 at 14:44
Andy Turner
73.6k873121
73.6k873121
answered Aug 10 at 12:45
Eugene
57.9k978136
57.9k978136
3
Where does the term "type witness" come from? I can't find it in the language spec.
â Andy Turner
Aug 10 at 12:50
3
@AndyTurner docs.oracle.com/javase/tutorial/java/generics/⦠search for "type witness", I was not saying it's in theJLS
(might be, not sure)
â Eugene
Aug 10 at 12:51
4
@Lino the official java tutorial calls it that way, I'll stick to that :)
â Eugene
Aug 10 at 12:56
2
The word "witness" doesn't appear in JLS (9, at least). They are simply calledTypeArguments
there.
â Andy Turner
Aug 10 at 12:58
1
@AndyTurnerTypeArguments
it is! thank you
â Eugene
Aug 10 at 13:00
add a comment |Â
3
Where does the term "type witness" come from? I can't find it in the language spec.
â Andy Turner
Aug 10 at 12:50
3
@AndyTurner docs.oracle.com/javase/tutorial/java/generics/⦠search for "type witness", I was not saying it's in theJLS
(might be, not sure)
â Eugene
Aug 10 at 12:51
4
@Lino the official java tutorial calls it that way, I'll stick to that :)
â Eugene
Aug 10 at 12:56
2
The word "witness" doesn't appear in JLS (9, at least). They are simply calledTypeArguments
there.
â Andy Turner
Aug 10 at 12:58
1
@AndyTurnerTypeArguments
it is! thank you
â Eugene
Aug 10 at 13:00
3
3
Where does the term "type witness" come from? I can't find it in the language spec.
â Andy Turner
Aug 10 at 12:50
Where does the term "type witness" come from? I can't find it in the language spec.
â Andy Turner
Aug 10 at 12:50
3
3
@AndyTurner docs.oracle.com/javase/tutorial/java/generics/⦠search for "type witness", I was not saying it's in the
JLS
(might be, not sure)â Eugene
Aug 10 at 12:51
@AndyTurner docs.oracle.com/javase/tutorial/java/generics/⦠search for "type witness", I was not saying it's in the
JLS
(might be, not sure)â Eugene
Aug 10 at 12:51
4
4
@Lino the official java tutorial calls it that way, I'll stick to that :)
â Eugene
Aug 10 at 12:56
@Lino the official java tutorial calls it that way, I'll stick to that :)
â Eugene
Aug 10 at 12:56
2
2
The word "witness" doesn't appear in JLS (9, at least). They are simply called
TypeArguments
there.â Andy Turner
Aug 10 at 12:58
The word "witness" doesn't appear in JLS (9, at least). They are simply called
TypeArguments
there.â Andy Turner
Aug 10 at 12:58
1
1
@AndyTurner
TypeArguments
it is! thank youâ Eugene
Aug 10 at 13:00
@AndyTurner
TypeArguments
it is! thank youâ Eugene
Aug 10 at 13:00
add a comment |Â
up vote
5
down vote
In:
BiPredicate<List<String>, String> contains2 = List::<String>contains;
<String>
is a type argument to a non-generic List.contains
method1.
While in:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
<String>
is a type argument to a List
.
1 - In this particular case a type argument is ignored according to the JLS ç15.12.2.1:
A non-generic method may be potentially applicable to an invocation
that supplies explicit type arguments. In such a case, the type
arguments will simply be ignored.
Is there any difference btw type parameter and type argument terms in this context? If yes, what is this?
â snr
Aug 10 at 18:41
1
Yes, there is a difference.E
inList<E>
is a type parameter and theString
inList<String>
is a type argument. You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument -String
in this case - to theList
itself (source).
â Oleksandr
Aug 10 at 19:09
thank you indeed
â snr
Aug 10 at 22:10
add a comment |Â
up vote
5
down vote
In:
BiPredicate<List<String>, String> contains2 = List::<String>contains;
<String>
is a type argument to a non-generic List.contains
method1.
While in:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
<String>
is a type argument to a List
.
1 - In this particular case a type argument is ignored according to the JLS ç15.12.2.1:
A non-generic method may be potentially applicable to an invocation
that supplies explicit type arguments. In such a case, the type
arguments will simply be ignored.
Is there any difference btw type parameter and type argument terms in this context? If yes, what is this?
â snr
Aug 10 at 18:41
1
Yes, there is a difference.E
inList<E>
is a type parameter and theString
inList<String>
is a type argument. You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument -String
in this case - to theList
itself (source).
â Oleksandr
Aug 10 at 19:09
thank you indeed
â snr
Aug 10 at 22:10
add a comment |Â
up vote
5
down vote
up vote
5
down vote
In:
BiPredicate<List<String>, String> contains2 = List::<String>contains;
<String>
is a type argument to a non-generic List.contains
method1.
While in:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
<String>
is a type argument to a List
.
1 - In this particular case a type argument is ignored according to the JLS ç15.12.2.1:
A non-generic method may be potentially applicable to an invocation
that supplies explicit type arguments. In such a case, the type
arguments will simply be ignored.
In:
BiPredicate<List<String>, String> contains2 = List::<String>contains;
<String>
is a type argument to a non-generic List.contains
method1.
While in:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
<String>
is a type argument to a List
.
1 - In this particular case a type argument is ignored according to the JLS ç15.12.2.1:
A non-generic method may be potentially applicable to an invocation
that supplies explicit type arguments. In such a case, the type
arguments will simply be ignored.
edited Aug 10 at 19:00
answered Aug 10 at 13:20
Oleksandr
6,55533263
6,55533263
Is there any difference btw type parameter and type argument terms in this context? If yes, what is this?
â snr
Aug 10 at 18:41
1
Yes, there is a difference.E
inList<E>
is a type parameter and theString
inList<String>
is a type argument. You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument -String
in this case - to theList
itself (source).
â Oleksandr
Aug 10 at 19:09
thank you indeed
â snr
Aug 10 at 22:10
add a comment |Â
Is there any difference btw type parameter and type argument terms in this context? If yes, what is this?
â snr
Aug 10 at 18:41
1
Yes, there is a difference.E
inList<E>
is a type parameter and theString
inList<String>
is a type argument. You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument -String
in this case - to theList
itself (source).
â Oleksandr
Aug 10 at 19:09
thank you indeed
â snr
Aug 10 at 22:10
Is there any difference btw type parameter and type argument terms in this context? If yes, what is this?
â snr
Aug 10 at 18:41
Is there any difference btw type parameter and type argument terms in this context? If yes, what is this?
â snr
Aug 10 at 18:41
1
1
Yes, there is a difference.
E
in List<E>
is a type parameter and the String
in List<String>
is a type argument. You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument - String
in this case - to the List
itself (source).â Oleksandr
Aug 10 at 19:09
Yes, there is a difference.
E
in List<E>
is a type parameter and the String
in List<String>
is a type argument. You can think of a generic type invocation as being similar to an ordinary method invocation, but instead of passing an argument to a method, you are passing a type argument - String
in this case - to the List
itself (source).â Oleksandr
Aug 10 at 19:09
thank you indeed
â snr
Aug 10 at 22:10
thank you indeed
â snr
Aug 10 at 22:10
add a comment |Â
up vote
4
down vote
Here's what Intellij tells me about them:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
Explicit type arguments can be inferred
BiPredicate<List<String>, String> contains2 = List::<String>contains;
Type arguments are redundant for the non-generic method reference
If you were to split these up into their respective lambda functions, I believe you'd see the following:
BiPredicate<List<String>, String> contains1 = (List<String> strings, String o) -> strings.contains(o);
BiPredicate<List<String>, String> contains2 = (strings, o) -> strings.<String>contains(o);
As we know, (List<String> strings, String o)
can be replaced by (strings, o)
and <String>
on the second line is unneeded (as String#contains
isn't generic), so it's safe to assume that both method references are equivalent.
add a comment |Â
up vote
4
down vote
Here's what Intellij tells me about them:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
Explicit type arguments can be inferred
BiPredicate<List<String>, String> contains2 = List::<String>contains;
Type arguments are redundant for the non-generic method reference
If you were to split these up into their respective lambda functions, I believe you'd see the following:
BiPredicate<List<String>, String> contains1 = (List<String> strings, String o) -> strings.contains(o);
BiPredicate<List<String>, String> contains2 = (strings, o) -> strings.<String>contains(o);
As we know, (List<String> strings, String o)
can be replaced by (strings, o)
and <String>
on the second line is unneeded (as String#contains
isn't generic), so it's safe to assume that both method references are equivalent.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Here's what Intellij tells me about them:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
Explicit type arguments can be inferred
BiPredicate<List<String>, String> contains2 = List::<String>contains;
Type arguments are redundant for the non-generic method reference
If you were to split these up into their respective lambda functions, I believe you'd see the following:
BiPredicate<List<String>, String> contains1 = (List<String> strings, String o) -> strings.contains(o);
BiPredicate<List<String>, String> contains2 = (strings, o) -> strings.<String>contains(o);
As we know, (List<String> strings, String o)
can be replaced by (strings, o)
and <String>
on the second line is unneeded (as String#contains
isn't generic), so it's safe to assume that both method references are equivalent.
Here's what Intellij tells me about them:
BiPredicate<List<String>, String> contains1 = List<String>::contains;
Explicit type arguments can be inferred
BiPredicate<List<String>, String> contains2 = List::<String>contains;
Type arguments are redundant for the non-generic method reference
If you were to split these up into their respective lambda functions, I believe you'd see the following:
BiPredicate<List<String>, String> contains1 = (List<String> strings, String o) -> strings.contains(o);
BiPredicate<List<String>, String> contains2 = (strings, o) -> strings.<String>contains(o);
As we know, (List<String> strings, String o)
can be replaced by (strings, o)
and <String>
on the second line is unneeded (as String#contains
isn't generic), so it's safe to assume that both method references are equivalent.
answered Aug 10 at 12:44
Jacob G.
12.7k31658
12.7k31658
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51786658%2fgeneric-method-reference-type-specifying-before-after-operator%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
7
Good question...
â ernest_k
Aug 10 at 12:35
Related: stackoverflow.com/questions/31245127/â¦. Seems the first syntax specifies type argument for
List
, whereas the second specifies type argument forcontains
(unnecessary in this case because the method is not generic)â ernest_k
Aug 10 at 12:44
3
And, of course,
BiPredicate<List<String>,String> contains1 = List<String>::<String>contains;
.â Andy Turner
Aug 10 at 12:45
2
As a related side-note, and a partial explanation: it's legal to supply type arguments to a non-generic method, such as
list.<Number>contains("foo")
. They're just ignored. (As for why the JLS authors chose to allow it, though, I don't know.)â Radiodef
Aug 10 at 16:53
1
@snr Why is it legal to supply type arguments to a non-generic method? You can find the answer here.
â Oleksandr
Aug 10 at 20:03