3

I have a List type of ( java.awt.List ) like following:

final List lstA = new List();

during add item to this list , there is a strikethrough on addItem:

enter image description here

and give me warning like following:

The method addItem(String) from the type List is deprecated

however program works fine.
what is causes this strikethrough on addItem?

Samiey Mehdi
  • 9,184
  • 18
  • 49
  • 63
  • 3
    It's not clear what you expect from an answer which isn't already in the warning: the method you're using is deprecated. – Jon Skeet Oct 09 '13 at 10:16
  • Hint: if you move your mouse over it, does a tooltip appear? Hint2: in any decent IDE, there is a list of issues somewhere not-so-hidden... – ppeterka Oct 09 '13 at 10:16

5 Answers5

5

Strike through methods means that these are deprecated methods. A deprecated method is the one that was for the older version of language and a new, better method has been provided for the same purpose. However the older version is also available for use, for those who have not learned about the new method and upgrading to newer version smoothly step by step.

you can learn about all the deprecated things in java and their new form / syntax Here http://docs.oracle.com/javase/7/docs/api/deprecated-list.html

learn all about AWT Lists here

http://docs.oracle.com/javase/7/docs/api/java/awt/List.html

Tauseef
  • 2,035
  • 18
  • 17
2

Because it is deprecated. You can see here

You can use

public void add(String item)

Adds the specified item to the end of scrolling list.

EDIT
1. See full list of deprecated methods java 7
2. is-it-wrong-to-use-deprecated-methods-or-classes-in-java

Community
  • 1
  • 1
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
1

Getting Strikethrough on method means that method has been Deprecated from API.

@Deprecated have a meaning

A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. Compilers warn when a deprecated program element is used or overridden in non-deprecated code.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
1

Use add method instead of addItem like following :

lstA.add("Red");
lstA.add("Blue");
lstA.add("Green");
Samiey Mehdi
  • 9,184
  • 18
  • 49
  • 63
0

strikethrough means that the method is deprecated and would not be available in next versions. You have to use other methods instead of this.

Zeeshan Saleem
  • 149
  • 4
  • 15