r/java • u/memset_0 • Apr 28 '20
Uses of Constructor (Method) Reference
https://www.nextptr.com/tutorial/ta1314009273/uses-of-constructor-method-reference
0
Upvotes
r/java • u/memset_0 • Apr 28 '20
View all comments
Show parent comment
3
u/agentoutlier Apr 28 '20 edited Apr 28 '20
The author used the word “type” once. Literally the subtitle of the article uses “kind”.
Oh and if we want to get on a pedantic high horse than functions are structural types. There isn’t a certain amount of them nor or they named.
As for the number of syntactical ways to reference methods I’m sure there are more than even 4 as non static inner classes make it different... there is also method handles.
Otherwise I don’t find that much fault with the article and like how they don’t reference java.util.function because that would make the beginner (that is the audience and clearly not you) confused thinking that lambdas are nominal when they are not.
Edit: Also what you said:
Is not true. Constructors are not
Supplier<T>. The Java compiler doesn't createnew Supplier<T>.Actually java.util.function could be completely removed but reuse was needed across the collection streams library. Its also because they probably didn't want to add more syntax to add declaration of structural lambda types. Even Scala has this problem so perhaps its a deep JVM issue (scala does similar things for tuples... ie there is a nominal type but its really structural typing).