aspose file tools*
The moose likes Beginning Java and the fly likes error: no interface expected here Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "error: no interface expected here" Watch "error: no interface expected here" New topic
Author

error: no interface expected here

Peter Simon
Greenhorn

Joined: Oct 25, 2002
Posts: 14
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.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Sorry to be a pedant but do you really mean
extends Serializable?
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Volodymyr Shram
Ranch Hand

Joined: Oct 17, 2002
Posts: 47
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

Joined: Oct 25, 2002
Posts: 14
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

Joined: Aug 03, 2002
Posts: 7729
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

Joined: Oct 17, 2002
Posts: 47
Originally posted by Barry Gaunt:
Volodymyr got in before me ( while I had to go for my books )

Peter Simon
Greenhorn

Joined: Oct 25, 2002
Posts: 14
Ok, I think I got it.
Barry is fast, but Volodymyr is even faster.
Thanks for helping me out guys.
Peter Simon
Greenhorn

Joined: Oct 25, 2002
Posts: 14
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 ;
{

}
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
>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

Joined: Oct 25, 2002
Posts: 14
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

Joined: Aug 03, 2002
Posts: 7729
OK you have overridden Object.equals(Object), now
you should provide a suitable int hashCode()
method.
Peter Simon
Greenhorn

Joined: Oct 25, 2002
Posts: 14
That's what I did Barry
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
I meant that as an assignment for next week
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error: no interface expected here