• Post Reply Bookmark Topic Watch Topic
  • New Topic

vector.contains() limits  RSS feed

 
Barak Pinch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's say I made a new class called Employee.

On another class "Firm", I created a vector like that:
Then I created a method in Firm class, which is adding objects (Employee X, Student extends Employee Z, Cashier extends Employee T, etc..) to that vector.

Now I want to add Z (Student extends employee) only if T (Cashier extends Employee) was already added.
I don't want to check specifically for T but for any Cashier type. So I want to check if any cashier was added, so I wrote:



It doesn't work.
It says: cannot find symbol, symbol= variable cashier, location= class firm.

How can I make it work?
thanks!
 
Barak Pinch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, when I later want to pick a random employee I write



it displays an error about the cashi=Employees.elementAt:

incompatible types
required: Employee
found: Object

why is it betraying me?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barak Pinch wrote:It doesn't work.

Not surprising, because contains() is used to find an object, NOT an object type.

How can I make it work?

Well, assuming you need this sort of functionality (which seems odd to me), there's nothing you can do except roll your own, viz:I'd also advise not using Vector; it's a legacy class from the days before the Java Collection Framework. ArrayList is usually just as good, and a lot faster.

Winston
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!