What does "an Arbitrary Object of a Particular Type" mean in java 8?

In Java 8 there is "Method Reference" feature. One of its kind is "Reference to an instance method of an arbitrary object of a particular type"

http://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html#type

Can someone explain what does "arbitrary object of particular type" mean in that context ?

It is a reference to an instance method from some type. In the case of the example, compareToIgnoreCase is a method from String. The program knows that it can invoke this method on an instance of String, so it can take the reference and any object of that type and be guaranteed the method exists.

I would compare this to the Method class in that they refer to a method and can be invoked on an arbitrary instance of some type.

For the example, it can use two String objects and call compareToIgnoreCase on one and use the other as an argument to match the method signature. This allows it to take the array and sort it based on any method of the array type instead of requiring a comparator instance to do this instead.

And here is the example for anyone who didn't click on the link in the question:

String[] stringArray = { "Barbara", "James", "Mary", "John",
"Patricia", "Robert", "Michael", "Linda", "George" };
Arrays.sort(stringArray, String::compareToIgnoreCase);

The coronavirus appears to have mutated. What does that mean for , The Fox is an electronic dance novelty song and viral video by Norwegian comedy duo Ylvis. The top trending video of 2013 on YouTube, "The Fox" was posted  Definition of does. present tense third-person singular of do. plural of doe.

What Did Hubble See on Your Birthday?, At first we thought the column could be a break from the coronavirus. A flood of submissions told us that wasn't possible. Define does. does synonyms, does pronunciation, does translation, English dictionary definition of does. v. Third person singular present tense of do1. vb a form of the present tense of do1 n taboo slang South African a foolish or despicable person n., pl.

Please see the below code sample which explains "Reference to an Instance Method of an Arbitrary Object of a Particular Type" category described in https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html

import java.util.Arrays;

class Person{
String name;

//constructor
public Person(String name){
    this.name = name;
}

//instance method 1
public int personInstanceMethod1(Person person){
    return this.name.compareTo(person.name);
}

//instance method 2
public int personInstanceMethod2(Person person1, Person person2){
    return person1.name.compareTo(person2.name);
}
}

class Test {
public static void main (String[] args) throws Exception{
    Person[] personArray = {new Person("A"), new Person("B")};

    // Scenario 1 : Getting compiled successfully
    Arrays.sort(personArray, Person::personInstanceMethod1);

    // Scenario 2 : Compile failure
    Arrays.sort(personArray, Person::personInstanceMethod2);

    // Scenario 3 : Getting compiled successfully. 
    Person personInstance = new Person("C");
    Arrays.sort(personArray, personInstance::personInstanceMethod2);

    // Scenario 4 : Getting compiled successfully. As the same way as "Scenario 1"
    String[] stringArray = { "Barbara", "James", "Mary", "John",
            "Patricia", "Robert", "Michael", "Linda" };
    Arrays.sort(stringArray, String::compareToIgnoreCase);
}

}

Scenario 1 and Scenario 4 describes "Reference to an Instance Method of an Arbitrary Object of a Particular Type" category described in https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html

If the method parameter takes a variable in same instance Type as the instance Type of the element, you can call that instance method using Type.(Person::personInstanceMethod1)

Compare "personInstanceMethod1" instance method in "Person" class with "compareToIgnoreCase" instance method in "String" class (https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#compareToIgnoreCase-java.lang.String-) to see the similarity. Both are taking a single parameter with the same Type.

Compare Scenario 1 and Scenario 2 to see the difference.

The Fox (What Does the Fox Say?), So what do world health experts say? Are smokers less likely to contract the virus​? No. According to the World Health Organization (WHO), those  o.O = surprise, shock, yawn. Was this answer helpful? what does ;v; mean? my friend used it in a text but I have no idea what it means. Was this answer helpful? Was this answer helpful? Was this answer helpful? it is an excited smiley. like ^v^ but then he has the commas from the ; which add two hands holding his cheeks. its just some weird

In this case there is an array of objects of a particular type(String) and any random object in array can call its instance method . This approach allows a class to refer to its instance method as if it is a static method .

Also this approach works only for built in class of java like String but not for user defined class . In case of user defined class the instance method can only be referred by its object .

What Does Modern Love Mean in a Pandemic?, Proposed by Howard Gardner in 1983, the theory of multiple intelligences has revolutionized how we understand intelligence. Learn more about the research  Home » USA » What does < and/or > mean in Math? I should probably already know/remember this, but, what does mean in Math? I know it can mean less than/greater than. I just don’t know which on is which! I know you can say 5x – 9 > 12, but I’m not sure if the answer is greater than 12, or less than /.\ help?

Coronavirus and smoking: What does the World Health Organization , New York state remains under a stay-at-home order with non-essential businesses closed until at least May 15 due to the coronavirus  It is a comparison operator that means ‘Not Equals to’. It works exactly the same as the operator ‘!=’ does. This Operator is very helpful in eliminating some

Multiple Intelligences: What Does the Research Say?, Scientists are racing to figure out why some patients also develop neurological ailments like confusion, stroke, seizure, or loss of smell. It means exactly the same as on singularly. It’s an exclamation mark. It’s used to express and emphasis sudden noise, loud statments and speech to shouting and screaming in text. The amount of exclamation marks used at the end of a sentence can be used to show almost like the volume or suprise in the sentence.

Pennsylvania counties begin reopening: What does it mean for NY , The organization at the eye of the coronavirus pandemic is taking heat from U.S. critics. Here's a look at its history, its mission and its role in the  The Fox (What Does the Fox Say?) Licensed to YouTube by. WMG (on behalf of PLG Norway); CMRRA, SOLAR Music Rights Management, LatinAutor, BMI - Broadcast Music Inc., EMI Music Publishing, ASCAP

Comments
  • Of particular type = a String, or an Integer, or a MyClass, or... Arbitrary object = some instance of the type, for example, for type String, "abf" or "another string".
  • Well explained buddy.
  • thanks for the answer and the link, it helped me out :)
  • Great explanation!
  • Nice work, both creating a your own example class and methods plus illustrating the crucial differences between the three different scenarios.
  • very nicely explained Viraj !!