This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics Question" Watch "Generics Question" New topic
Author

Generics Question

Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97


This question is from javabeat
could anyone explain??
Andriy Pererva
Ranch Hand

Joined: Jul 19, 2009
Posts: 73
The warning is because raw List reference is referenced to parametrized LinkedList.
LinkedList parametrization means that you have an intent to explcitly restrict collection items to String type, but the raw reference spoils all the generic effort and allows to add any object (like Integer on line 7), despite of LinkedList parametrization


SCJP 6.0(95%), SCWCD 5(94%), SCJD (working on B&S v.2.3.1)
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
But the rule is:

Non Generic ref. type + Generic instant --> compiles w/o warning
Generic ref.type + Non Generic instant --> compiles with warning
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17


This line of code does not generate any compiler warning. How did you compile your code?? Did you use any IDE??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Chandana Garlapati
Ranch Hand

Joined: Jul 06, 2009
Posts: 97
Ankit Garg wrote:
This line of code does not generate any compiler warning. How did you compile your code?? Did you use any IDE??


No i am trying in notepad and command prompt.
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi Chandana..

i think you need to use Netbeans or other Java IDE..
it could help us to know the warning..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Dragos Nica
Ranch Hand

Joined: Oct 25, 2009
Posts: 39
Chandana Garlapati wrote:
Ankit Garg wrote:
This line of code does not generate any compiler warning. How did you compile your code?? Did you use any IDE??


No i am trying in notepad and command prompt.


The warning will occur only if you are trying to add something.
Every time when you try to add something to a non parameterized collection , the warning will occur. As such a list can accept any type of object, this is the compiler's way to tell you that you must pay attention to what you are adding to the list.


SCJP 6.0 (88%)
 
wood burning stoves
 
subject: Generics Question