This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Error in method signature Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error in method signature" Watch "Error in method signature" New topic

Error in method signature

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

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

I Hear I Forget, I See I Remember, I Do I Understand.
Ernie Mcracken
Ranch Hand

Joined: Feb 13, 2011
Posts: 33

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...

You're on a gravy train with biscuit wheels Roy.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

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.

How To Ask Questions How To Answer Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46435
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.
I agree. Here's the link:
subject: Error in method signature
It's not a secret anymore!