This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Tamas Szekeres
Greenhorn
Posts: 6
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37051
507
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!