Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

No generic type checking at all for raw types?

Thread view: 
Christopher Benson-Manica - 10 Oct 2006 17:47 GMT
Consider this very simple code:

import java.util.*;

public class Test {
 private static class Foo<T> {
   public List<String> foo(List<String> param) {
     return param;
   }
 }

 public static void main(String[] args) {
   Foo f = new Foo();
   List<String> bar = f.foo(new ArrayList<String>());
 }
}

f is a member of the raw type Foo, and therefore as expected the code
produces a warning about an unchecked call to foo() when compiled with
-Xlint:unchecked.  What I don't understand, however, is why there is
also a warning about an unchecked conversion from java.util.List to
java.util.List<java.lang.String>.  Why is the compiler unable to
determine that foo does in fact return a List<String> and not a raw
List?  Or is the compiler output simply overstating the case?

Signature

C. Benson Manica           | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com      | don't, I need to know.  Flames welcome.

Piotr Kobzda - 10 Oct 2006 21:29 GMT
> Why is the compiler unable to
> determine that foo does in fact return a List<String> and not a raw
> List?   Or is the compiler output simply overstating the case?

All this is deeply discussed there:
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.8

piotr


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.