Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object or ArrayList Syntax Error

 
Justin Tom
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I'm sorta new to Java and OOP and I have this funny error in this method:



What I'm trying to do is to just look at the object on top of the stack because I'm trying to solve a problem about matching brackets together by using stacks and I'm treating each character of a string as their own object.


The error says:


I hope it's just one of my dumb mistakes but I can't figure out how to fix it or why that error happened?
 
Henry Wong
author
Marshal
Pie
Posts: 20892
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is *not* a valid method signature. Not sure what you are trying to do -- you want to define a method that returns a method?

Henry
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Justin T., welcome to JavaRanch. Please check your private messages. You can see them by clicking My Private Messages.
 
Justin Tom
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use the peek method such that when I'm "peeking" into my stack, I won't get an error when the top of the stack is empty. I guess my problem is the return type... but I defined s as

in a constructor. So, shouldn't the return type should be an ArrayList for the peek method? If no why not?
 
Justin Tom
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
think I got it now. Silly me, it should have been returning of type Object, not arraylist.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic