type parameter in ArrayList

Hi all,

I need to know the reason why the name of type parameter is not allowed to be the same as class name . For example,

import java.util.Random;

import java.awt.Color;

import java.awt.Graphics;

import java.util.ArrayList;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class bouncingBalls {

static ArrayList<bouncingBalls> list = new ArrayList<bouncingBalls>();

bouncingBalls a=new bouncingBalls();

list.add(a);

public static void main(String[] args) {

}

}

Please help. Thanks.

[627 byte] By [kevinchanga] at [2007-11-27 6:58:25]
# 1

try this:

public class bouncingBalls

{

static ArrayList<bouncingBalls> list = new ArrayList<bouncingBalls>();

static bouncingBalls a = new bouncingBalls(); // needs static here

// list.add(a); // this needs to be in a method

public static void main(String[] args)

{

list.add(a);

}

}

also, when posting code, please use code tags. Read up on them [url=http://forum.java.sun.com/help.jspa?sec=formatting]here[/url].

Message was edited by:

petes1234

petes1234a at 2007-7-12 18:49:03 > top of Java-index,Java Essentials,New To Java...