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.

Recommended Answers

All 3 Replies

Please copy and paste here the full text of the error message.

Use ob.getClass() ? rather than T.class

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.