What's the difference between instance method reference types in Java 8?

前端 未结 3 1470
感情败类
感情败类 2020-11-27 06:16

So Java 8 introduces method references and the docs describe the four types.

My question is what\'s the difference between the two instance types?

3条回答
  •  自闭症患者
    2020-11-27 06:29

    1. myString::charAt would take an int and return a char, and might be used for any lambda that works that way. It translates, essentially, to index -> myString.charAt(index).

    2. String::length would take a String and return an int. It translates, essentially, to string -> string.length().

    3. String::charAt would translate to (string, index) -> string.charAt(index).

提交回复
热议问题