Samiey Mehdi
Samiey Mehdi

Reputation: 9424

Why there is strikethrough on addItem method of List?

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?

Upvotes: 3

Views: 4553

Answers (5)

Tauseef
Tauseef

Reputation: 2052

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

Upvotes: 5

Samiey Mehdi
Samiey Mehdi

Reputation: 9424

Use add method instead of addItem like following :

lstA.add("Red");
lstA.add("Blue");
lstA.add("Green");

Upvotes: 1

Suresh Atta
Suresh Atta

Reputation: 122006

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.

Upvotes: 1

Zeeshan Saleem
Zeeshan Saleem

Reputation: 149

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

Upvotes: 0

Aniket Kulkarni
Aniket Kulkarni

Reputation: 12993

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

Upvotes: 2

Related Questions