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