• Post Reply Bookmark Topic Watch Topic
  • New Topic

Gui calling method  RSS feed

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to call this method

from dropoutstack class
and this is how I do it in my gui class

but i'm getting this error

I'm still having a hard time understanding this OOP why doesn't this find newElement?
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you declare newElement ?
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok I didn't declare newElement, so I'm assuming that whenever there are parameters you must declare them then. It's type T so how would I declare that?
 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dustin Schreader wrote:ok I didn't declare newElement, so I'm assuming that whenever there are parameters you must declare them then. It's type T so how would I declare that?



Yes, you would have to declare any variable being used in the code. As far as the type T is concerned, it would work as follows-

So if your newElement is of type- String, then T would be String. Implicitly this type information will be passed to the method you are invoking.
Actually the type T would depend on the type information being provided while creating the instance of the class. Can you provide us the DropOutStack class definition?
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when you are creating the instance of DropOutStack, you should be using this:


Also please check the pop() method- it isnt returning anything?

 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I added the DropOutStack<String> myStack = new DropOutStack<String>(); to the method already but I guess I need to declare newElement so How do I do that?

In my DropOutStack class I was just overriding the pop method from my linked stack class.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dustin Schreader wrote:I think I added the DropOutStack<String> myStack = new DropOutStack<String>(); to the method already but I guess I need to declare newElement so How do I do that?

In my DropOutStack class I was just overriding the pop method from my linked stack class.



The newElement can be declared as-


And also check the pop method defined in LinkedStackClass- pretty strange that it doesnt return the popped value. You might want to explore the Collection classes from the Java library.
 
You don't like waffles? Well, do you like this tiny ad?
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!