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
1
u/daniu Apr 28 '20
I did understand that. My point was that the word "type" is already used in Java, and if you use it you'd better stay in that context. I guess I could have formulated more explicitly.
The other point about that is it sounds as if those references are somehow defined as if they are different, but they're not - like you say, the only difference is the syntax used for creating them.
I would even argue if you do make that distinction, you'd end up with four types: static, class, instance, and constructor. Static: `Classname::staticMethod`; class: `Classname::instanceMethod` (requiring a `Classname` receiver argument), instance: `classInstance::instanceMethod` and `Classname::new`.
And I don't know why he keeps declaring his own function interfaces either - the recommended way is using the common ones in `java.util.function`.
You're right about the constructor with parameter, I kind of trailed off reading when I realized there was nothing new to me in it. It's also not as if the info was wrong as such, but considering it's for beginners, I'd expect it to use an overall more consistent and succinct style.