Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

why this method returns the object's reference?  RSS feed

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, can you please tell me what i have done wrong because this method returns the object's reference and not its value.
thank you for help


 
Saloon Keeper
Posts: 2339
293
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a close look at line #12.
 
rian bron
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Take a close look at line #12.



damn thank you XD
 
Ranch Hand
Posts: 483
23
AngularJS Eclipse IDE Firefox Browser Java Spring VI Editor
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

rian bron wrote:damn thank you XD


I will add up one thing make it your habbit to use @Override annotation when overriding the Object class methods or the super class methods. this will be an extra information to compiler for what you are intending is overriding the super class method. Try to test it on your version of your code posted...
 
Master Rancher
Posts: 1061
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

praveen kumaar wrote:
I will add up one thing make it your habbit to use @Override annotation when overriding the Object class methods or the super class methods. this will be an extra information to compiler for what you are intending is overriding the super class method. Try to test it on your version of your code posted...


Or simply let your ide generate them for you, less room for error...
 
Marshal
Posts: 62819
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:. . . Or simply let your ide generate them for you, less room for error...

Afraid that wouldn't help in the beginners' forum; if an IDE recognises the method as overridden and suggests the @Override annotation, the annotation becomes irrelevant because the IDE “knows” that the method is overridden correctly.
That annotation is intended for compile‑time; it catches minor errors like...and the user knows that an error has occurred almost immediately. But I agree that you should always use that annotation if appropriate.
 
Saloon Keeper
Posts: 9707
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Campbell. The point of the @Override annotation is to let the compiler know that you intended to override something, so it can check that the method signature is exactly the same as that of a method you inherited. The IDE can only generate this annotation for you if the signature already matches, so that would be a case of putting the cart before the horse. Of course you can let your IDE generate it if you don't feel like typing, but you need to check it manually: it's not a good idea to let such annotations be auto-generated without verifying that the annotations have indeed been placed where you intended to place them.
 
Daniel Demesmaecker
Master Rancher
Posts: 1061
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't mean to let the ide generate the annotation, but the whole toString method... I never write my own constructors, getters/setters or toStringmethods (enless they have some special logic, what almost never is the case)
 
Stephan van Hulst
Saloon Keeper
Posts: 9707
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh okay I see. Yes, that's definitely a possibility.

Congrats on your 1000th post by the way.
 
Daniel Demesmaecker
Master Rancher
Posts: 1061
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Campbell Ritchie
Marshal
Posts: 62819
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I didn't mean to let the ide generate the annotation, but the whole toString method... . . .

But on the beginner's forum, people need practice writing toString() methods, etc.
 
a fool thinks himself to be wise, but a wise man knows himself to be a fool - shakespeare. foolish tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!