0

hello,
i have a question--- i have to implement arraylist by using array.
and i m using following approach-

package DS;

import java.lang.reflect.Array;

public class ArrayList<T> {
	T ob[];

	public ArrayList(Class<T []> c, int s) {
		// Use Array native method to create arra of a type only known at run
		// time
		ob = c.cast( Array.newInstance(c.getComponentType(), s));
	}

	@SuppressWarnings("unchecked")
	void addItem(T item)
		{
			for(int i=0;i<ob.length;i++)
			{
				if(!isFull(i))
				{
					ob[i]=item;	
				}
				
			}
			
		@SuppressWarnings("rawtypes")
		ArrayList a=new ArrayList(T.class, ob.length);
			
			
		}

	boolean isFull(int i) {

		if (ob[i] == null) {
			return false;
		}

		return true;
	}

what is prob in the line (red line)...there is no error if i write is for String.

Edited by __avd: Added [code] tags.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by NormR1
0

I think Generics types only exist at compile time.
Read the Tutorial for more information.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.