Marking unused parameters with underscores

Suppose that you are served four food items at a restaurant, but you don't eat three of them. If the restaurant has a protocol for customers to mark ort (which literally means used) and non-ort food items, the food from the table can be used in a certain manner. For example, the restaurant can mark the non-ort items as good to eat, and can consider sharing them with the needy.

Similarly, when calling a method or a lambda expression, you might not need all of the method parameters. In that case, communicating your intent to the compiler (that certain parameters aren't used) is a good idea. This has two benefits—it saves the compiler from type-checking the values that are not required, and it saves you from passing any arbitrary values to match the code definition and code-calling syntax.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.24.106