We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Generic class (Read 1560 times)
Generic class
Jul 31st, 2007, 9:20am
 
Trying to use a generic class:

I copied this Stack class from a book, but it wont compile,
bugging on the 1st line:

class Stack<Item>  ( unexpected token "<" )

Any suggestion ?

//
//Stack = Stack as a Simply-Linked List, storing items
//====================
class Stack<Item> {
 private int count;
 private Node head;

 Stack<Item>() {
   head=null;
   count=0;
 }//Stack

 boolean isEmpty() {
   return (head==null);
 }

 void reset() {
   head=null;
   count=0;
 }//reset()

 void push(Item item0) {
   head=new Node(item0,head);
   count++;
 }//push()

 Item pop() {
   Item v=head.item;
   head=head.next;
   count--;
   return v;
 }//pop()

 //====================
 private class Node<Item> {
   private Item item;
   private Node<Item> next;

   Node(Item item0) {
     item=item0;
     next=null;
   }

   Node(Item item0,Node<Item> next0) {
     item=item0;
     next=next0;
   }

 }//private class Node

}//class Stack
Re: Generic class
Reply #1 - Jul 31st, 2007, 9:43am
 
Processing uses Java 1.4, generics are part fo java 1.5 and higher.

To use them within prcessing you'll need to ether download thr "without java" version, and have java 1.5 or higher installed, or replace the java folder in processing with a 1.5 version.
Re: Generic class
Reply #2 - Jul 31st, 2007, 10:46am
 
this is not gonna work (i think), because Processings precompiler (ANTLR) will still have problems with the java-1.5 syntax.

http://dev.processing.org/bugs/show_bug.cgi?id=598

F
Re: Generic class
Reply #3 - Jul 31st, 2007, 2:41pm
 
http://processing.org/faq.html#java
http://processing.org/reference/environment/platforms.html#java
Re: Generic class
Reply #4 - Aug 1st, 2007, 8:12am
 
Thank you all for the informations and references.
So I will forget about generics,
I can do without them anyway.
Page Index Toggle Pages: 1