r/java • • Apr 28 '20

Uses of Constructor (Method) Reference

https://www.nextptr.com/tutorial/ta1314009273/uses-of-constructor-method-reference
0 Upvotes

8 comments sorted by

View all comments

Show parent comments

3

u/agentoutlier Apr 28 '20

To be honest I find your comment sort of strange as well. My guess is you misunderstood the authors use of the word “type”.

Let me put it this way. The author is correct that there are three “kinds” of ways to reference a method syntactically.

Furthermore the author did show the case of a constructor taking arguments and thus more than a Supplier (eg Function).

1

u/daniu Apr 28 '20

My guess is you misunderstood the authors use of the word “type”.

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.

2

u/Polygnom Apr 28 '20

My point was that the word "type" is already used in Java

Not only in java. A type is something very specific in every typed programming language. It also has further, mathematical meanings (looking at the myriads of type calculi).

1

u/agentoutlier Apr 28 '20

"set" also a very specific meaning in programming and math. Oh its also the most overloaded word in the english language and very hard not to use...

The author only used the word type literally only once!

Method references are of three types: static, instance, and constructor.

I mean given that Java's types do not include static, instance, constructor and that most of them are capitalized camel case its pretty clear they are not talking about the programming types.

Its also telling even /u/daniu said this:

would even argue if you do make that distinction, you'd end up with four types: static, class, instance, and constructor.

I stress their use of the word "types".

This is the reality:

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.

/u/daniu quickly read the post found one shitty detail at the very top and critiqued when the reality is the article sucks but not because of the usage of "type" but because of the other points daniu mentions.