• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error: no interface expected here

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have two classes which extend interfaces.
One extends Serializable, the other javax.ejb.EntityBean
I do import the right packages.
java.io.Serializable
and
javax.ejb.*
Compiler complains: no interface expected here.
I guess the solution is pretty straightforward, but I don't see what I'm doing wrong.
thanks for setting this straight.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to be a pedant but do you really mean
extends Serializable?
-Barry
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Peter Simon:
Hi,
I have two classes which extend interfaces.
One extends Serializable, the other javax.ejb.EntityBean
I do import the right packages.
java.io.Serializable
and
javax.ejb.*
Compiler complains: no interface expected here.
I guess the solution is pretty straightforward, but I don't see what I'm doing wrong.
thanks for setting this straight.


Yeah, Barry Gaunt is right, you have to use
implement instead of extends interfaces in your case:

or extends inteface for local/remote interface:

and
implement your serializable object:

...
 
Peter Simon
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for the replys.
As I thought it was pretty straightforward.
Have to get used interpreting the errormessages I guess.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Volodymyr got in before me ( while I had to go for my books )
You must implement EntityBean.
Damm... I'll just have to learn to type with four fingers...
[ October 25, 2002: Message edited by: Barry Gaunt ]
 
Volodymyr Shram
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Barry Gaunt:
Volodymyr got in before me ( while I had to go for my books )


 
Peter Simon
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I think I got it.
Barry is fast, but Volodymyr is even faster.
Thanks for helping me out guys.
 
Peter Simon
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry and Volodymyr,
Maybe you can help me with this one aswell...
I have to write a method which as an argument receives an object.
The method has to check with instanceOf wether it is an object of a certain type,(in my case CabinPK)and if so check wether a variable of that object is equal to a variable from the class which implements the method equals.
It seems that the object received as an argument has to be casted to CabinPK first before being able to compare variables.
Would you know how to do this?
Here is my code for what it is worth:
public boolean equals(Object obj){
if(obj instanceof CabinPK == true)
{
if (obj.id == this.id){
return true ;
{

}
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>It seems that the object received as an argument >has to be casted to CabinPK first before being >able to compare variables.
Once you have successfully tested the class of an object with intanceof, you can safely cast it with (classname)varname. Until you do so, the object is only an Object. It will behave as a CabinPK for just that call when you are casting it.
If you want to make multiple calls to something, each require casting, you can use a local variable for help:

For your problem:

Bill
 
Peter Simon
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bill,
I managed to write this:
public boolean equals(Object obj){
boolean result = false;
if(!(obj instanceof CabinPK ))
return false;
{
CabinPK pk = (CabinPK)obj;
if(pk.id == this.id)
{
result = true;
}
return result;
}
but yours defenitly is better.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK you have overridden Object.equals(Object), now
you should provide a suitable int hashCode()
method.
 
Peter Simon
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I did Barry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant that as an assignment for next week
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic