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 / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

Generics code won't compile

Thread view: 
Jo Vermeulen - 28 May 2004 14:55 GMT
Hello,

I'm trying to compile a simple Node class using Generics, but it won't
compile. I'm using Sun JDK 1.5.0 beta 1 on GNU/Linux (Gentoo Linux).

This is my code:

package datastructures;

import java.util.Iterator;
import java.util.LinkedList;

/**
* @author Jo Vermeulen
*/
public class Node {
    public Node(char content) {
        this.children = new LinkedList<Node>();
        this.content = content;
    }
   
    public boolean hasChildWithContent(char c) {
        for (Node e: children) {
            if (c == e.getContent()) {
                return true;
            }
        }
       
        return false;
    }
   
    /**
    * @return Returns the children.
    */
    public LinkedList<Node> getChildren() {
        return children;
    }
   
    /**
    * @return Returns the content.
    */
    public char getContent() {
        return content;
    }
   
    /**
    * @param content The content to set.
    */
    public void setContent(char content) {
        this.content = content;
    }
   
    private LinkedList<Node> children;
    private char content;   
}

And these are the errors:

$ javac Node.java
Node.java:11: '(' or '[' expected
               this.children = new LinkedList<Node>();
                                             ^
Node.java:16: ';' expected
               for(Node e: children) {
                         ^
Node.java:23: illegal start of expression
       }
       ^
Node.java:28: <identifier> expected
       public LinkedList<Node> getChildren() {
                        ^
4 errors

Any ideas? According to the Generics tutorial on java.sun.com this should
compile :-s Do I have to use a commandline option for compiling generics
code?

Kind regards,

Signature

Jo Vermeulen
Student Computer Science at the tUL
email: jo@lumumba.luc.ac.be
www: http://lumumba.luc.ac.be/jo

Jo Vermeulen - 28 May 2004 14:58 GMT
Op Fri, 28 May 2004 15:55:19 +0200, schreef Jo Vermeulen:

> Hello,
>
> I'm trying to compile a simple Node class using Generics, but it won't
> compile. I'm using Sun JDK 1.5.0 beta 1 on GNU/Linux (Gentoo Linux).

Hmmm, got it to compile using "javac -source 1.5 Node.java", but don't
know if this a correct commandline option?

Kind regards,

Signature

Jo Vermeulen
Student Computer Science at the tUL
email: jo@lumumba.luc.ac.be
www: http://lumumba.luc.ac.be/jo

Andrew Thompson - 28 May 2004 15:05 GMT
> I'm trying to compile a simple Node class using Generics, but it won't
> compile. I'm using Sun JDK 1.5.0 beta 1 on GNU/Linux (Gentoo Linux).

Try the ..
javac -source 1.5
compile option, looks like it might do the trick

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology



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.