开发者

How to Use the Stack class in the [closed]

开发者 https://www.devze.com 2023-03-26 13:17 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a Parameter class which just has parameters

Parameter
{

 String inputfilename;
 int numA;
 double numbB;
  etc...
}

and ProcessParameter class that has methods defined

ProcessParameter
{
  openParameters
  {

     //Open file and read the parameters into the Parameter object
     BufferedReader openFile = new Buf开发者_开发百科feredReader(new FileReader(parameterFileName));
     String[] tokens = openFile.readLine().trim().split(DELIMITER); 
     Parameter openparameter = new Parameter();     
     openParameter.setInputFileName(tokens[0]);

     openFile.readLine();
     openParameter.setNumA = Integer.parseInt(tokens[0]);

}

My Question is : How do I use stack directly on the Parameter Class? *( i have about 15 parameters in the parameter class and will be using Update, save and open methods in the ProcessParameter class)*

I was trying:

     Stack<Parameter> stack = new Stack<Parameter>();
     stack.push(tokens[0]);

     openFile.readLine();
     **stack.push(Integer.parseInt(tokens[0]));**

I get this warning: The method push(Parameter) in the type Stack is not applicable for the arguments (int) Would really appreciate any pointers and thanks for the help.


You're trying to push an int when you said the Stack should contain Parameter instances.

You'll either need to change the generic type of stack or change how you store your tokens.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号