1

I have the following class which extends JFrame

@SuppressWarnings("serial")
public class View extends JFrame{
   //bla bla bla bla code
}

Now I have the following sub class:

public class Foo extends View{

   //bla bla bla bla
}

In the View class Eclipse is giving me a warning so I added SuppressWarnings to get rid of it.I thought that by doing this I wouldn't have to retype SuppressWarnings in the Foo class but as it seems eclipse is giving me a warning on Foo class.Should this be happening?

cssGEEK
  • 994
  • 2
  • 15
  • 38

2 Answers2

2

@SuppressWarnings is an example of an annotation in Java. What you want is to let Foo inherit the annotations of View.

However, that's not possible in Java. This question is describing why it's not possible (namely because otherwise multiple-inheritance could occur as interface methods can have annotations as well.

When Eclipse is giving you a warning you should not ignore it generally. Try to make Eclipse happy because it only warns you if it has a very good reason to do so. If you're really confident that in your program a SuppressWarnings is suitable, then all subclasses must use that same annotation as well.

Community
  • 1
  • 1
Joost Verbraeken
  • 883
  • 2
  • 15
  • 30
1

JFrame implements Serializable interface. For the class that implements Serializable, eclipse would ask it to have a serialVersionUID.

View extends from JFrame, we can say it also implements Serializable interface. So does Foo, and that's reason why you need to add serialVersionUID or add Suppress-Warning for both View and Foo.

Eugene
  • 10,627
  • 5
  • 49
  • 67