• Post Reply Bookmark Topic Watch Topic
  • New Topic

"Add type arguement to " warning  RSS feed

 
rajnish patel
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
when I declare any data structure in eclipse, I get following "WARNING".

"Add type arguement to "any data structure"

i.e.
from
Iterator it = al.iterator();
to
Iterator<String> it = al.iterator();


Can any one explain me what does it mean ??
and what if we use it and if don't use it..
 
sanchit dua
Ranch Hand
Posts: 31
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generics introduce following advantages over non-generic classes-
1. Type Safety
2. Explicitly type conversions are not required.

We get the same output then why we need Generics when we can get same output by ordinary method?

The following example demonstrates the use of Generics.







Now, we are doing some changes in the last program to make GenericTest.java.


// Compile time Error:
Type mismatch: cannot convert from A<String> to A<Integer>


Type safety is the feature of detecting incompatible assignments at compilation time. In case of Generics each reference variable is given a type at the time of declaration hence, incompatible assignments are detected whereas incase of non-generic classes incompatible assignments are not detected usually when references of parent type are used to hold child objects.

Please let me know if it answers your question.

Regards,

Sanchit
 
Khuzema Dharwala
Ranch Hand
Posts: 61
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajnish can you paste the declaration of "al" here ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!