Forums Register Login

error: no interface expected here

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Sorry to be a pedant but do you really mean
extends Serializable?
-Barry
+Pie Number of slices to send: Send
 

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:

...
+Pie Number of slices to send: Send
thank you for the replys.
As I thought it was pretty straightforward.
Have to get used interpreting the errormessages I guess.
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
 

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


+Pie Number of slices to send: Send
Ok, I think I got it.
Barry is fast, but Volodymyr is even faster.
Thanks for helping me out guys.
+Pie Number of slices to send: Send
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 ;
{

}
+Pie Number of slices to send: Send
>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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
OK you have overridden Object.equals(Object), now
you should provide a suitable int hashCode()
method.
+Pie Number of slices to send: Send
That's what I did Barry
+Pie Number of slices to send: Send
I meant that as an assignment for next week
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 16386 times.
Similar Threads
Help with this mortgage calculation program
JFileChooser Filter Problem
declaring variables
Java noob needs help
lets see if someone can solve this mistry
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:14:09.