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 / July 2006

Tip: Looking for answers? Try searching our database.

newbie question on generics error

Thread view: 
gmail.5.mbrna@xoxy.net - 12 Jul 2006 06:34 GMT
hi. I'm attempting to learn some java. Currently following the
Collections Trail
at http://java.sun.com/docs/books/tutorial/collections/index.html

On this page
http://java.sun.com/docs/books/tutorial/collections/interfaces/list.html
is an example of sublisting:
public static <E> List<E> dealHand(List<E> deck, int n) {
   int deckSize = deck.size();
   List<E> handView = deck.subList(deckSize - n, deckSize);
   List<E> hand = new ArrayList<E>(handView);
   handView.clear();
   return hand;
}

When I paste that into a file and try to compile with javac, I get
'class' or 'interface' expected
public static <E> List<E> dealHand(List<E> deck, int n)
--------------^
(the carat is pointing to the first < char on the line)

javac -version reports: javac 1.5.0_07

What am I doing wrong?
thanks,
mikey.
Oliver Wong - 12 Jul 2006 15:56 GMT
> hi. I'm attempting to learn some java. Currently following the
> Collections Trail
[quoted text clipped - 20 lines]
>
> What am I doing wrong?

   That's a code snippet, and not a complete source file. Specifically, the
code you're seeing there is a method declaration. It needs to be inside of a
class declaration. You might want to back up and learn the grammar of Java
before moving onto things like the Collections API.

   http://java.sun.com/docs/books/tutorial/java/javaOO/classes.html

   - Oliver


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



©2008 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.