• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help Me Understand Java Interface  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


My question is if I declare an Interface Vehicle how can I check if the Vehicle is an Audi or Toyota?
I tried to do the following in eclipse

And the error I get back is: Incompatible operand types Class<capture#1-of ? extends ILoBuddy> and MTLoBuddy
 
masl ali
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


My question is if I declare an Interface Vehicle how can I check if the Vehicle is an Audi or Toyota?
I tried to do the following in eclipse

And the error I get back is: Incompatible operand types Class<capture#1-of ? extends ILoBuddy> and MTLoBuddy
Also how can I get the model from Audi through the Vehicle interface.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
masl ali wrote:And the error I get back is: Incompatible operand types Class<capture#1-of ? extends ILoBuddy> and MTLoBuddy

No you aren't. At least not from the code you posted. I suspect you've missed out stuff that uses those classes.

However, I think that what you're looking for is the instanceof operator. For more information, you should really check the tutorials.

Winston
 
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this with code:



 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you were looking for this thing only.
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see some very bad design there. A Toyota is not a kind of vehicle, nor is an Audi. They are manufacturers. Now, class Car implements Vehicle, or class Van implements Vehicle sounds a lot better.

And a driver is not a String.
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I can see some very bad design there. A Toyota is not a kind of vehicle, nor is an Audi. They are manufacturers. Now, class Car implements Vehicle, or class Van implements Vehicle sounds a lot better.


I am considering the OP's example.
 
Campbell Ritchie
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ishan Pandya wrote: . . . I am considering the OP's example.
So was I.

It does nobody any good to let poor code escape unchallenged. That would be a bit like a driving instructor who lets a learner drive through a red light because they were learning how to change gear at that moment.
 
Ishan Pandya
Ranch Hand
Posts: 228
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
It does nobody any good to let poor code escape unchallenged. That would be a bit like a driving instructor who lets a learner drive through a red light because they were learning how to change gear at that moment.


Yes sir got it. I will see to it next time.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!