I need to create a myStack class and then use it to test for Palindromes... I chose to create an ArrayList based implementation of the stack.
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 a class called Palindrome (not complete yet)
However, when I compile, it tells me "Note: Palindrome.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details."
When I comment out the line myStack m = new myStack(test);
It compiles, so I know this is the problem... Why would the myStack class be the problem? Is it something to do with the "AnyType" I used in the stack class?