Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Question about Method Reference

 
Ranch Foreman
Posts: 122
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a quesiton. The Class::method can have the following two meanings:

How does the compiler differentiate the two scenarios, and decide if the "a" is the first parameter or the object to call method on?
 
Frank Mi
Ranch Foreman
Posts: 122
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some search online, I found Java does NOT differentiate the two case and doesn't compile while ambiguity happens. I'm so sad.  

 
Saloon Keeper
Posts: 22668
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't be sad. Many years ago I was called on to write a C++ compiler and in C++, ambiguities were not fatal.

At the time, they were also not - so far as I could see - predictable. So that shot down that project.
 
Saloon Keeper
Posts: 12430
269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Tim. Resolve ambiguity explicitly and don't let the compiler guess. If you insist on using method references instead of lambda expressions, you can just make a private method in your class that acts as an alias for the method you really want to call.
 
Frank Mi
Ranch Foreman
Posts: 122
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you two. Thanks.
 
"To do good, you actually have to do something." -- Yvon Chouinard
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic