• 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
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Error in method signature

 
Ranch Hand
Posts: 82
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
I just beginning learn object oriented programming and I've developed this class and works well, but the last method flag this suggestion "Add@Override Annotation"
can anyone tell me why???
further, I'd be grateful if you give me any advices about this class
Thanks in advance
 
Ranch Hand
Posts: 33
Mac Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm just learning java too.. as far as I know this is because your method has the signature toString which means you are overriding the toString method of the object class which is the implicit superclass of all other classes. So this is just a suggestion for you to add the annontation to you code to say your are overriding a method of the superclass.

Hope this helps...
 
Sheriff
Posts: 22813
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Annotations. This one isn't required, but it's a good practice to always use the @Override annotation. That prevents you from making typos:
Since the method name is hashCode, with capital C, this is not overriding so there will be a compiler error.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A general remark about your code:

The fan speed is set by an integer and you have defined 3 constants for the speed settings. However it's perfectly legal to call it with: fan.setSpeed(5000); (if 3 is fast then how fast would 5000 be ). A better way would be to define an enum.
 
Marshal
Posts: 79827
388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And it might be a good idea to make the final fields public. Then other classes can invoke them to set the fan's speed.

As an atlernative, you can set bounds and refuse to alter the speed if it is outwith the permitted speed range (in your case 0-3 inclusive, using 0 as "stop"). Wouter's suggestion of an nenum is far better, however.
 
Do not threaten THIS beaver! Not even with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic