• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

generics compilation...

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
How can the following statement will compile?The mock exam says it will compile.Can anyone clarify me?Thanks.

list < ? super String> list = new ArrayList <String> ();
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain why it wouldn't compile (assuming the type "List" is capitalized)?
 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In the exam it was using '& with lt' and '& with gt' for < and > symbols.I copied the same symbols in this post.But it is changed as normal symbols < and >.But I don't know why?I think in Sun Exam the generics type will always be inside < and > not with in '& with lt' and '& with gt'.
--------------------------------------------------------------------------------
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kathir,

see your second post.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

list<? super String> l = new ArrayList<String>



assuming 'l' in list is capital..this syntax is perfectly fine..
because <? super String> means anything above in the inheritance hierarchy including String..

take another example...


List<? super Ferrai> list ---> then you can make it to refer to either Ferrari or Car or Vehicle or Object !!
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kathir vel:
...In the exam it was using '& with lt' and '& with gt' for < and > symbols.I copied the same symbols in this post.But it is changed as normal symbols < and >.But I don't know why? ...


The less-than and greater-than symbols have special meaning in HTML. So to display these symbols in HTML, the sequences &lt; and &gt; are used. It appears that for some reason, your browser was not displaying these sequences as the intended symbols.

(Note: To get these sequences to appear here without being displayed as the symbols, I used the sequence for the ampersand, &amp;. That is, &amp;lt; and &amp;gt;.)
[ July 25, 2007: Message edited by: marc weber ]
 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic