I need to create the myStack class and then use it to test Palindromes ... I decided to create an ArrayList-based stack implementation.
import java.util.ArrayList;
public class myStack<AnyType>{
private ArrayList<AnyType> arr;
public myStack(ArrayList<AnyType> a){
arr = a;
}
public void push(AnyType element) {
arr.add(element);
}
public AnyType pop() {
if(arr.size() == 0)
{
System.out.println("Stack Underflow");
return null;
}
else
{
AnyType element = arr.get(arr.size() -1);
arr.remove(element);
return element;
}
}
public AnyType top() {
if(arr.size() == 0)
{
System.out.println("Stack Underflow");
return null;
}
else
return(arr.get(arr.size() -1));
}
}
Then I use it in the Palindrome class (not completed yet)
However, when I compile, this tells me Note: Palindrome.java uses unverified or insecure operations. Note. Recompiling with -Xlint: unchecked for details. "
When I comment out the line myStack m = new myStack (test);
It compiles, so I know this is a problem ... Why would myStack class be a problem? Is this somehow related to the "AnyType" that I used in the stack class?