• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

OCA / OCP Java SE 8 Programmer Practice Tests: Chapter 13 Question 40 Errata

 
Greenhorn
Posts: 6
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question is:

Why can’t String::charAt be used as a method reference?


Offered answers:

A. Method references can only be used on static methods.
B. Method references can pass either the instance or the parameter from the lambda, but not both.
C. The charAt() method takes an int rather than Integer parameter.
D. There is no charAt() method in the String class.


Answer, according to Answers to Review Questions:

B. ... With method references, only one item can be supplied at runtime. Here, we need either a String instance with no parameters in the method or a static method with a single parameter. The charAt() method is an instance method with a single parameter so does not meet this requirement.


Correct answer: it can be used as a method reference:

 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're right! It never occurred to me to do this! Let's pretend the question says "with a Function" because that's the only way to save it .

I've given you a cow for this great find and added it to the errata
 
straws are for suckers. tiny ads are for attractive people.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic